- attached filter-o2o.py
Comparison to None on one-to-one relation does not generate proper query
While comparison to None in one-to-many relations works, for one-to-one it generates completely wrong query, as illustrated in filter-o2o.py
Also, != comparison to None in uselist=False case generates somewhat non leading exception, in contrast to case uselist=True.
But, it seems to me that it isn't much work to extend the ne to work as negated eq in comparison to None (in case of uselist=False, at least).
I've attached a simple patch which cures above mentioned - but it should be taken only as example of what I'm talking about, because I haven't dig into the rest of comparators and don't really understand the code.
Comments (6)
-
Account Deleted -
Account Deleted - attached simple-patch.txt
Simple patch that cures filter-o2o.py in both ==None and !=None cases (but probably breaks something else)
-
repo owner - changed status to resolved
very nice. You're on the right track but I corrected the patch to check specifically for the "ONETOMANY" "direction", since thats actually whats at play here, and added unit tests for all o2m/m2o/o2o combinations of ==None/!=None in 3175686514dc75acfa3ed0be92f31535325c60dd. thanks for the patch / test !
-
Account Deleted - removed status
- changed status to open
This patch has broken ==None comparison for the one-to-many relations though the secondary table.
filter(Folder.parent == None) now results in
SELECT folder.id AS folder_id, folder.name AS folder_name FROM folder, folder_hier WHERE folder.id = folder_hier.child AND folder_hier.parent IS NULL ORDER BY folder.oid
instead of (before the patch applied)
SELECT folder.id AS folder_id, folder.name AS folder_name FROM folder WHERE NOT (EXISTS (SELECT 1 FROM folder_hier WHERE folder.id = folder_hier.child)) ORDER BY folder.oid
-
Account Deleted - attached test.py
a testcase
-
repo owner - changed status to resolved
- Log in to comment
Example test case for wrong generation of relation query on backref o2o