summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-08-09 13:31:14 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-08-17 14:25:41 -0400
commit6370d6b15f52abdbbadca3707e3722b984daff53 (patch)
tree815ff17fa3abf13deb71c1b25e4ec0d4e1935e8a /lib/sqlalchemy/orm/attributes.py
parentd1187812efe0d85c050c9d99f59523bb7ecaa6ee (diff)
downloadsqlalchemy-6370d6b15f52abdbbadca3707e3722b984daff53.tar.gz
validate mapped collection key is loaded
Changed the attribute access method used by :func:`_orm.attribute_mapped_collection` and :func:`_orm.column_mapped_collection`, used when populating the dictionary, to assert that the data value on the object to be used as the dictionary key is actually present, and is not instead using "None" due to the attribute never being actually assigned. This is used to prevent a mis-population of None for a key when assigning via a backref where the "key" attribute on the object is not yet assigned. As the failure mode here is a transitory condition that is not typically persisted to the database, and is easy to produce via the constructor of the class based on the order in which parameters are assigned, it is very possible that many applications include this behavior already which is silently passed over. To accommodate for applications where this error is now raised, a new parameter :paramref:`_orm.attribute_mapped_collection.ignore_unpopulated_attribute` is also added to both :func:`_orm.attribute_mapped_collection` and :func:`_orm.column_mapped_collection` that instead causes the erroneous backref assignment to be skipped. Fixes: #8372 Change-Id: I85bf4af405adfefe6386f0f2f8cef22537d95912
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
0 files changed, 0 insertions, 0 deletions