diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-27 21:15:01 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-27 21:31:18 -0400 |
| commit | aaba0650d7410f579b2c14f8f1b0680a1d1852c4 (patch) | |
| tree | 22909a68b1802aa5fefa12a276040414e6aa8ec2 /lib/sqlalchemy | |
| parent | 4c6f10d7a3665e895b095db2f29ad04a9ac71ded (diff) | |
| download | sqlalchemy-aaba0650d7410f579b2c14f8f1b0680a1d1852c4.tar.gz | |
ensure relationship.order_by stored as a tuple; check in dynamic also
Fixed regression in dynamic loader strategy and :func:`_orm.relationship`
overall where the :paramref:`_orm.relationship.order_by` parameter were
stored as a mutable list, which could then be mutated when combined with
additional "order_by" methods used against the dynamic query object,
causing the ORDER BY criteria to continue to grow repetitively.
Fixes: #6549
Change-Id: I9f4c9a723aa0923f115cbe39bfaaa9cac62153b1
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/dynamic.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py index ac7eba03b..5cc00dbff 100644 --- a/lib/sqlalchemy/orm/dynamic.py +++ b/lib/sqlalchemy/orm/dynamic.py @@ -66,6 +66,7 @@ class DynamicAttributeImpl(attributes.AttributeImpl): supports_population = False collection = False dynamic = True + order_by = () def __init__( self, @@ -82,7 +83,8 @@ class DynamicAttributeImpl(attributes.AttributeImpl): class_, key, typecallable, dispatch, **kw ) self.target_mapper = target_mapper - self.order_by = order_by + if order_by: + self.order_by = tuple(order_by) if not query_class: self.query_class = AppenderQuery elif AppenderMixin in query_class.mro(): diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 00a14b04c..efdd7edf1 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -2208,12 +2208,12 @@ class RelationshipProperty(StrategizedProperty): # ensure expressions in self.order_by, foreign_keys, # remote_side are all columns, not strings. if self.order_by is not False and self.order_by is not None: - self.order_by = [ + self.order_by = tuple( coercions.expect( roles.ColumnArgumentRole, x, argname="order_by" ) for x in util.to_list(self.order_by) - ] + ) self._user_defined_foreign_keys = util.column_set( coercions.expect( |
