property of a polymorphic mapper on a polymorphic mapper don't work

Issue #493 resolved
Former user created an issue

in the following schema:

+-------------------------------------------*
|   people (abstract) --- has a --- car     |
|         ^    ^                     ^      |
|         |    |                     |      |
| engineers    managers            offroad  |
|                                           |
+-------------------------------------------+

you define a ploymorphic car_mapper for car and offroad you define a polymorphic people_mapper for engineers and managers with a property 'car' relation(car_mapper)

after clearing the session, if you query a Person and you retrieve his car property (person.car), the object returned is wrong but the reference to the car (person.car_id) is right. see attached test case

Comments (5)

  1. Former user Account Deleted

    After a lot of investigation, the problem seems to come from the test at line 282 of orm/strategies.py. At this time, I don't know how that occurs but in our case,

    ...
     if leftcol is not rightcol and should_bind(rightcol, leftcol):
    ...
    

    return False. More precisely, the 'should_bind' return False. A little test with this previous line replaced by

     if True: #leftcol is not rightcol and should_bind(rightcol, leftcol):
    

    And all work fine. I'll try to continue my investigation... if you have any idea...

  2. Mike Bayer repo owner

    OK unfortunately my fixes that i released in 0.3.5 were not 100% complete as this involves the correct list of columns being indicated as "remote", which is then used by the lazy loader to generate "sometable.x = ?" (i.e. the bind param)...basically if the "remote" column is in the child mapper and the child mapper is polymorphic the column will probably not be detected and the lazy clause will probably come out wrong, and I also was able to reveal this issue after adding some complexity to an existing test in inheritance5.py.

    anyway it was an easy fix and is in changeset:2362, its just now we have to wait til 0.3.6 for proper relationships between polymorphic mappers.

  3. Mike Bayer repo owner

    oh also your polymorphic union doesnt work in postgres which chokes on the duplicate "car_id" column in the cars->outerjoin->offroad.select(), it has to be written as:

            car_join = polymorphic_union(
                {
                    'car' : cars.select(offroad_cars.c.car_id == None, from_obj=[cars.outerjoin(offroad_cars)](cars.outerjoin(offroad_cars))),
                    'offroad' : cars.join(offroad_cars)
                }, "type", 'car_join')
    
  4. Former user Account Deleted

    Thank you for your job and your support!!! I hope that I'll be able in the future to fix by myself bugs and to contribute more closely to the project.

  5. Log in to comment