You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/08/06 18:48:07 UTC

[GitHub] [incubator-superset] etr2460 opened a new pull request #10537: fix: revert "chore: Cleanup database sessions (#10427)"

etr2460 opened a new pull request #10537:
URL: https://github.com/apache/incubator-superset/pull/10537


   This reverts commit 7645fc85c3d6676a13ae76ca5133f83d8fb54dbe.
   
   ### SUMMARY
   #10427 broke saving queries in sql lab with the following error:
   ```
   /Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py:2505: SAWarning: Usage of the 'Session.add()' operation is not currently supported within the execution stage of the flush process. Results may not be consistent.  Consider using alternative event listeners or connection-level operations instead.
     "event listeners or connection-level operations instead." % method
   ERROR:flask_appbuilder.models.sqla.interface:Add record error: This transaction is closed
   Traceback (most recent call last):
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2597, in _flush
       flush_context.execute()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
       rec.execute(self)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/unitofwork.py", line 624, in execute
       uow,
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 326, in delete_obj
       _organize_states_for_delete(base_mapper, states, uowtransaction)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 463, in _organize_states_for_delete
       base_mapper, uowtransaction, states
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/persistence.py", line 1602, in _connections_for_states
       connection = uowtransaction.transaction.connection(base_mapper)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 311, in connection
       self._assert_active()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 304, in _assert_active
       raise sa_exc.ResourceClosedError(closed_msg)
   sqlalchemy.exc.ResourceClosedError: This transaction is closed
   During handling of the above exception, another exception occurred:
   Traceback (most recent call last):
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/flask_appbuilder/models/sqla/interface.py", line 585, in add
       self.session.commit()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 162, in do
       return getattr(self.registry(), name)(*args, **kwargs)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1036, in commit
       self.transaction.commit()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 503, in commit
       self._prepare_impl()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 482, in _prepare_impl
       self.session.flush()
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2496, in flush
       self._flush(objects)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2637, in _flush
       transaction.rollback(_capture_exception=True)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 81, in __exit__
       compat.raise_(value, with_traceback=traceback)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
       raise exception
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2637, in _flush
       transaction.rollback(_capture_exception=True)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 519, in rollback
       self._assert_active(prepared_ok=True, rollback_ok=True)
     File "/Users/erik_ritter/repos/github.com/incubator-superset/venv/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 304, in _assert_active
       raise sa_exc.ResourceClosedError(closed_msg)
   sqlalchemy.exc.ResourceClosedError: This transaction is closed
   ```
   
   This reverts the PR and attempts to fix the merge conflicts on top of it as I couldn't find any specific line at fault here
   
   ### TEST PLAN
   CI, saving queries work
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   to: @john-bodley @bkyryliuk @dpgaspar @villebro 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] john-bodley commented on a change in pull request #10537: fix: revert "chore: Cleanup database sessions (#10427)"

Posted by GitBox <gi...@apache.org>.
john-bodley commented on a change in pull request #10537:
URL: https://github.com/apache/incubator-superset/pull/10537#discussion_r466651659



##########
File path: superset/sql_lab.py
##########
@@ -132,7 +132,8 @@ def session_scope(nullpool: bool) -> Iterator[Session]:
         )
     if nullpool:
         engine = sqlalchemy.create_engine(database_uri, poolclass=NullPool)
-        session_class = sessionmaker(bind=engine)
+        session_class = sessionmaker()

Review comment:
       @etr2460 this was the only thing which I wonder was wrong. In the [docs](https://docs.sqlalchemy.org/en/13/orm/session_api.html#session-and-sessionmaker) where they recommend:
   
   > The class also includes a method configure(), which can be used to specify additional keyword arguments to the factory, which will take effect for subsequent Session objects generated. This is usually used to associate one or more Engine objects with an existing sessionmaker factory before it is first used:
   > 
   > ```
   > # application starts
   > Session = sessionmaker()
   >
   > # ... later
   > engine = create_engine('sqlite:///foo.db')
   > Session.configure(bind=engine)
   > ```
   
   however we're not doing anything between creating and configuring the session.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] etr2460 commented on a change in pull request #10537: fix: revert "chore: Cleanup database sessions (#10427)"

Posted by GitBox <gi...@apache.org>.
etr2460 commented on a change in pull request #10537:
URL: https://github.com/apache/incubator-superset/pull/10537#discussion_r466665044



##########
File path: superset/sql_lab.py
##########
@@ -132,7 +132,8 @@ def session_scope(nullpool: bool) -> Iterator[Session]:
         )
     if nullpool:
         engine = sqlalchemy.create_engine(database_uri, poolclass=NullPool)
-        session_class = sessionmaker(bind=engine)
+        session_class = sessionmaker()

Review comment:
       I don't believe this code is even run when trying to save a query. the session used here is only for running the query i thought?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] villebro commented on pull request #10537: fix: revert "chore: Cleanup database sessions (#10427)"

Posted by GitBox <gi...@apache.org>.
villebro commented on pull request #10537:
URL: https://github.com/apache/incubator-superset/pull/10537#issuecomment-670167153


   I can't help but wonder if it's the scoped sessions at play.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [incubator-superset] etr2460 merged pull request #10537: fix: revert "chore: Cleanup database sessions (#10427)"

Posted by GitBox <gi...@apache.org>.
etr2460 merged pull request #10537:
URL: https://github.com/apache/incubator-superset/pull/10537


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org