[Sqlalchemy-tickets] Issue #3456: Cannot initialize or set relations with tuples (zzzeek/sqlalchemy
Brought to you by:
zzzeek
|
From: dwt <iss...@bi...> - 2015-06-17 08:05:15
|
New issue 3456: Cannot initialize or set relations with tuples https://bitbucket.org/zzzeek/sqlalchemy/issue/3456/cannot-initialize-or-set-relations-with dwt: In our applications we like to use immutable types where not otherwise needed, just as a default to prevent bugs where you get a collection set on your object and then it changes without you noticing because it's actually a shared value and somebody else still thinks he owns it. Since these bugs are very hard to spot, we like to use tuple() over list() to alleviate that concern. SQLA however insists on list() or list-like structures for initializing or set to many relations. Since it already does quite a lot to adapt whatever type is incoming that might be iterable in any sensible way - can't it not also support tuples? We're seeing this crop up (using declarative) in object initialization in code like ``User(groups=(group1, group2))`` or ``user.groups = (group1, group2)`` As far as I can see ``adapt_like_to_iterable`` seems to be the culprit here as it only accepts the mutable variants of the types. |