[Bug 15759] New: Allow Koha::Object derived objects to be used as hashrefs
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Bug ID: 15759 Summary: Allow Koha::Object derived objects to be used as hashrefs Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: gmcharlt@gmail.com Reporter: kyle@bywatersolutions.com QA Contact: testopia@bugs.koha-community.org On occasion, bugs in Koha have been revealed to be a mis-use of Koha::Object. This seems to be due to our long standing use of hashrefs for data in Koha. For instance, a developer may accidentally write: my $borrowernumber = $borrower->{borrowernumber}; instead of my $borrowernumber = $borrower->borrowernumber; Since our object is a blessed hashref, this does not cause an error. Instead, we just access that key of the hashref, which is almost certainly undefined. With some extra code in Koha/Object.pm, we can allow hashref-like use of our Objects, which will not only prevent these errors, but allow drop-in use of Koha::Objects where we currently use hashrefs! -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|gmcharlt@gmail.com |kyle@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 --- Comment #1 from Kyle M Hall <kyle@bywatersolutions.com> --- Created attachment 47740 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=47740&action=edit Bug 15759 - Allow Koha::Object derived objects to be used as hashrefs On occasion, bugs in Koha have been revealed to be a mis-use of Koha::Object. This seems to be due to our long standing use of hashrefs for data in Koha. For instance, a developer may accidentally write: my $borrowernumber = $borrower->{borrowernumber}; instead of my $borrowernumber = $borrower->borrowernumber; Since our object is a blessed hashref, this does not cause an error. Instead, we just access that key of the hashref, which is almost certainly undefined. With some extra code in Koha/Object.pm, we can allow hashref-like use of our Objects, which will not only prevent these errors, but allow drop-in use of Koha::Objects where we currently use hashrefs! Test Plan: 1) Apply this patch 2) prove t/db_dependent/Borrower.t -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |ASSIGNED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Jonathan Druart <jonathan.druart@bugs.koha-community.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart@bugs.koha-c | |ommunity.org -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 --- Comment #2 from Jonathan Druart <jonathan.druart@bugs.koha-community.org> --- This is an interesting approach, but I am not sure it will be good in the long term. At the moment, when we see ->method we know we are manipulating an object, and with ->{key} that we are manipulating a hashref. With this patch, we will never know easily. It will permit an easier and quicker switch to Koha::Objects in several areas, but it will hide the job to be done. We should at least warn/carp or use Koha::Log (debug) to know the places it is treated as a hashref. My thinking is still that that can be achieve (less easily but less magic) using ->unblessed. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 --- Comment #3 from Kyle M Hall <kyle@bywatersolutions.com> --- (In reply to Jonathan Druart from comment #2) Yes, I do agree with your points. I'm on the fence post about this. I think there is a possibility of confusion, but I think the ability of being able to drop objects into legacy code may outweigh those problems in the short term. Long term we should definitely work to using our objects properly. Unblessed is very useful, but as soon as you unbless an object it loses all its powers. If we were to add this feature I think it would be safest to only use it at the script level, and not in our modules. It would provide incredible benefits in some of our scripts where switching the code to objects is very non-trivial due to all the processing, munching and additions to hashrefs that take place. I'll bring it up at the next dev meeting so we can get a general consensus as to if this is a worthwhile feature to pursue. I'm fine with the decision going either way. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |alex.sassmannshausen@ptfs-e | |urope.com --- Comment #4 from Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com> --- (In reply to Kyle M Hall from comment #1)
Created attachment 47740 [details] [review] Bug 15759 - Allow Koha::Object derived objects to be used as hashrefs
On occasion, bugs in Koha have been revealed to be a mis-use of Koha::Object. This seems to be due to our long standing use of hashrefs for data in Koha.
For instance, a developer may accidentally write:
my $borrowernumber = $borrower->{borrowernumber};
instead of
my $borrowernumber = $borrower->borrowernumber;
Since our object is a blessed hashref, this does not cause an error. Instead, we just access that key of the hashref, which is almost certainly undefined.
I can see the problem here, but I am not sure about the proposed solution. I think the above should cause an error when it happens, rather than Koha trying to hide the error.
With some extra code in Koha/Object.pm, we can allow hashref-like use of our Objects, which will not only prevent these errors, but allow drop-in use of Koha::Objects where we currently use hashrefs!
To aid code legibility, it makes sense IMHO, to be clear about what we are using. The proposed change, while convenient, would obscure. In terms of the conversion to Koha::Objects, I think it is better to continue trudging through refactoring as we go. It's work that needs to be done anyway, and this is a good opportunity! Alex -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution|--- |WONTFIX -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|WONTFIX |--- Status|RESOLVED |REOPENED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Kyle M Hall <kyle@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |RESOLVED Resolution|--- |WONTFIX -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759 Jacek Ablewicz <abl@biblos.pk.edu.pl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |abl@biblos.pk.edu.pl -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org