From acfbbe198ef675d3a41fb383cb173c3e6acdf652 Mon Sep 17 00:00:00 2001 From: Daniel Lister Date: Thu, 24 Jan 2019 12:31:31 -0500 Subject: [PATCH] Added getter for query._execution_options Fixes: #4406 --- lib/sqlalchemy/orm/query.py | 9 +++++++++ test/orm/test_query.py | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 1503479951..340032e9b9 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -1554,6 +1554,15 @@ class Query(object): """ return self.with_hint(None, text, dialect_name) + def get_execution_options(self): + """ Get the non-SQL options which will take effect during execution. + + .. seealso:: + + :meth:`.Query.execution_options` + """ + return self._execution_options + @_generative() def execution_options(self, **kwargs): """ Set non-SQL options which take effect during execution. diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 0c8c27bb2c..4ec602e43c 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -5205,17 +5205,25 @@ class ExecutionOptionsTest(QueryTest): sess = create_session(bind=testing.db, autocommit=False) q1 = sess.query(User) - assert q1._execution_options == dict() + eq_(q1._execution_options, dict()) q2 = q1.execution_options(foo="bar", stream_results=True) # q1's options should be unchanged. - assert q1._execution_options == dict() + eq_(q1._execution_options, dict()) # q2 should have them set. - assert q2._execution_options == dict(foo="bar", stream_results=True) + eq_(q2._execution_options, dict(foo="bar", stream_results=True)) q3 = q2.execution_options(foo="not bar", answer=42) - assert q2._execution_options == dict(foo="bar", stream_results=True) + eq_(q2._execution_options, dict(foo="bar", stream_results=True)) q3_options = dict(foo="not bar", stream_results=True, answer=42) - assert q3._execution_options == q3_options + eq_(q3._execution_options, q3_options) + + def test_get_options(self): + User = self.classes.User + + sess = create_session(bind=testing.db, autocommit=False) + + q = sess.query(User).execution_options(foo="bar", stream_results=True) + eq_(q.get_execution_options(), dict(foo="bar", stream_results=True)) def test_options_in_connection(self): User = self.classes.User -- 2.47.3