]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Added getter for query._execution_options
authorDaniel Lister <dan.lister@gmail.com>
Thu, 24 Jan 2019 17:31:31 +0000 (12:31 -0500)
committerDaniel Lister <dan.lister@gmail.com>
Thu, 24 Jan 2019 17:42:18 +0000 (12:42 -0500)
Fixes: #4406
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index 150347995178cc7f4cb0b843f88ac590d053ace7..340032e9b955f693cb7fa729737b2d90919a9e8f 100644 (file)
@@ -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.
index 0c8c27bb2c7529298790b8270cd0aaf2c3dec900..4ec602e43cd757e28ef2c8def42b16a975db86db 100644 (file)
@@ -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