zzzeek / sqla_issue_test

1 stars 0 forks source link

Attempts to update/insert into irrelevant tables when using a polymorphic mapper #235

Closed zzzeek closed 6 years ago

zzzeek commented 18 years ago

Originally reported by: Anonymous


I was trying the latest version of SQLAlchemy and (after some trouble with SQLite caused by the fact that my home area is on a network share), I found a problem in the new polymorphic mapper support.

Specifically, with a set-up like

pjoin = polymorphic_union({
    'user':      principals.join(users),
    'group':     principals.join(groups),
    'principal': principals,
    }, 'type', 'pjoin')

and User, Group and Principal classes with the obvious inheritance relationships, it's possible that creating a new User object will cause SQLAlchemy to attempt to insert into groups table(!)

This fails in my case because I have attributes on Group objects (and in the groups table) that are set to nullable=False and don't correspond to any attribute in the users table.


zzzeek commented 18 years ago

Original comment by Michael Bayer (Bitbucket: zzzeek, GitHub: zzzeek):


we've worked this out in email, was a small user error

zzzeek commented 18 years ago

Original comment by Anonymous:


A test case plus a proposed fix for the problem.