Re: [sqlalchemy] Importing module from another subdirectory [UPDATE 2]
On Wed, 17 Apr 2019, Rich Shepard wrote: Getting closer. Added a blank __init.py__ in the models/ subdirectory. Now I'm looking for the proper syntax to import the relevant class within that module. So more work on my part. I'm moving this thread to the python mail list; it's a python issue not an SA issue. Trying to run the module using Python3-3.7.3's pdb I get the same error. Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Importing module from another subdirectory [UPDATE]
On Wed, 17 Apr 2019, Rich Shepard wrote: What is the proper syntax to import models as m a in a view module, e.g., activities.py? The syntax, 'import model as m' fails because it is not in the same subdirectory as the importing module. Getting closer. Added a blank __init.py__ in the models/ subdirectory. Now I'm looking for the proper syntax to import the relevant class within that module. import model.activities as a is not working: Traceback (most recent call last): File "activities_data_entry.py", line 1, in import model.activities as a ModuleNotFoundError: No module named 'model' So more work on my part. Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Tkinter search dialog box for model row
My web search for an existing Tkinter search dialog box found nothing. I'm looking for a pointer to a module or method if one exists. In this application the user needs to find database rows based on two class columns: lname and fname and display results in the appropriate data entry dialog view. Regards, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Importing module from another subdirectory
My application intends to follow the MVC pattern. The model.py module is ../model/model.py while the Tkinter views are in ../views/. Both are relative to the application's main directory: bustrac/ README.rst bustrac.py* controller/ images/ model/ scripts/ views/ What is the proper syntax to import models as m a in a view module, e.g., activities.py? The syntax, 'import model as m' fails because it is not in the same subdirectory as the importing module. My previous use of python has had all files in the same directory so I've not before had to learn how to address this issue. Pointers appreciated. Regards, Rich -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Commands out of sync; you can't run this command now
On Wednesday, April 17, 2019 at 4:36:30 AM UTC-4, tonthon wrote: > > May the scoped_session factory, used in both services (web and celery), > may cause such a problem ? > Apologies for my earlier reply, that would only affect exceptions in Celery. I do suggest checking your Celery code to make sure you are not connecting to the database before the fork - Celery does run as multi-processing by default. Celery can potentially use SqlAlchemy in two places: the messaging backend and the worker task runners. If you are using SqlAlchemy for the messaging backend, that is potentially the cause. If you are using another technology (Redis/Rabbit/etc) for messaging, Pyramid should never be invoking the scoped_session for Celery. In either situation, you can drop some debug lines around when the DB connection is made to ensure you're connecting at the right time. I've debugged issues in this area with PostgreSQL by enabling query logging and including the transaction id, then looking backwards at each error to find the query that broke the connection's state. If your issue happens frequently enough, an hour or two of logging might be enough to show you what happened. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Commands out of sync; you can't run this command now
Yes, celery is running in a separate service. The objects are never passed from the web app to the celery service, only ids are passed, Objects are then retrieved on the celery side. May the scoped_session factory, used in both services (web and celery), may cause such a problem ? Le 16/04/2019 à 15:41, Mike Bayer a écrit : On Tue, Apr 16, 2019 at 4:49 AM tonthon wrote: Celery tasks are using the same scoped_session factory, could it cause the errors we're facing here ? what's important is if these tasks run in the same process or not ? ( i thought celery runs as a separate service?) If you are passing ORM objects which are associated with a thread local Session in process to a Celery task queue which is running distinct threads in the same process, then yes that will exactly lead to this issue and needs to be fixed. You can't share a persistent (meaning, associated with a Session) ORM loaded object with another thread, because that means you are sharing the whole Session across threads. The object needs to be detached first (e.g. session.expunge(obj), or just session.close()) , or the celery thread needs to get just the primary keys and load the objects on its own.Another option is to merge() the objects into the Session to be used by the celery worker but this also has to be done carefully so that neither Session emits SQL on the wrong thread. Le 15/04/2019 à 15:39, Mike Bayer a écrit : On Mon, Apr 15, 2019 at 5:41 AM tonthon wrote: I tried to set a lower value for the pool_recycle value and it seems to work. There is a celery service running in the background, maybe it could affect the session management. this will reduce the problem but the architectural issue that is causing it is likely still present. I'd want to look at how the interaction with Celery is occurring within the same process. Le 12/04/2019 à 15:58, Mike Bayer a écrit : it's likely that a database connection is being returned to the pool in an invalid state. Switching to NullPool temporarily might reveal that this solves all the issues ; at the very least, I would try setting pool_recycle to a low number, like 5 minutes, however this won't prevent the problem, just make it less likely. What you do need to find are stack traces that precede the error, to give a clue why a connection would be placed in the pool in a bad state. The other possibility is that your application is actually sharing a single connection across threads in some way which would be a different problem though with a lot of similar behaviors. Are there any global in-memory caches being used of objects where an ORM object might be shared out among threads, or a background worker thread of some kind, anything like that ?Does the application use a "scoped_session" pattern and maybe the session being passed around in some cases isn't actually scoped? On Fri, Apr 12, 2019 at 4:03 AM tonthon wrote: Le 10/04/2019 à 17:12, Mike Bayer a écrit : On Wed, Apr 10, 2019 at 9:23 AM tonthon wrote: Hi, We're using sqlalchemy in a Pyramid Web Application. We use the ZopeTransactionExtension and our session factory is initialized this way : DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) We use the pyramid_tm that wraps each web requests in a transaction. Our services are served through apache and mod_wsgi (1 process, 10 threads). We recently faced the following error : 193.253.40.35 - 2019-04-08 09:29:23,054 ERROR Exception during reset or similar ([sqlalchemy.pool.QueuePool._finalize_fairy:721]) Traceback (most recent call last): File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 712, in _finalize_fairy fairy._reset(pool) File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/pool.py", line 881, in _reset self._reset_agent.rollback() File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1632, in rollback self._do_rollback() File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1670, in _do_rollback self.connection._rollback_impl() File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 706, in _rollback_impl self._handle_dbapi_exception(e, None, None, None, None) File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception exc_info File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 704, in _rollback_impl self.engine.dialect.do_rollback(self.connection) File "/var/www/autonomie/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 1804, in