zzzeek / test_sqlalchemy

0 stars 0 forks source link

Comparison to None on one-to-one relation does not generate proper query #985

Closed sqlalchemy-bot closed 16 years ago

sqlalchemy-bot commented 16 years ago

Issue created by Anonymous


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.


Attachments: simple-patch.txt | filter-o2o.py | test.py

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


Simple patch that cures filter-o2o.py in both ==None and !=None cases (but probably breaks something else)

sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


ab5adea36079f23c2436be10a303a5840bd16c21

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


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
sqlalchemy-bot commented 16 years ago

Michael Bayer (zzzeek) wrote:


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 !

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


a testcase

sqlalchemy-bot commented 16 years ago

Anonymous wrote:


Example test case for wrong generation of relation query on backref o2o

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: set attachment to "simple-patch.txt"

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: removed "resolved" state

sqlalchemy-bot commented 16 years ago

Changes by Michael Bayer (zzzeek): set state to "resolved"

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: set attachment to "test.py"

sqlalchemy-bot commented 16 years ago

Changes by Anonymous: set attachment to "filter-o2o.py"