-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: staleness
option can't be changed while a transaction is in progress
#192
Comments
@odino, oh, I guess I know what's happening. By default, you're in with engine.begin() as connection:
connection.execute(...) Otherwise you're returning a connection back to connections pool, but there is a transaction in progress on the connection. As |
@IlyaFaer thanks for your pointer -- I do assume that is the problem. Though I see you're working on a PR, as it would be convenient not having to commit / roll it back manually eg. when you're executing just some random selects. I actually did not realize everything ran in the context of a tx here. |
BTW one thing to note, when I switch to
|
The issue is resolved now, will do a release with the fix and update here. |
The fix is now released with the latest version. |
When v1.1.0 will be available at PyPI ? |
Hi @kazshinohara, It looks like the release failed which is why it is not available on PyPI. Unfortunately, the issue for the failure was closed by a bot before we saw it so we weren't aware of this until now. I'm looking into this issue now and will let you know when it has been successfully published to PyPI. Apologies for the inconvenience! |
@larkee Thanks !! I'm planning to talk about this ORM at an user community in Japan next month, hopefully the release wil be landed soon. |
hey @vi3k6i5 -- as @kazshinohara mentioned, the v1.1.0 release has failed, any tentative date it woud be released?
|
Hi any update on this ? |
Hi @asthamohta , please take a look. |
Hi @kazshinohara, @IlyaFaer has figured out the issue and will push a solution by tomorrow so hopefully by early next week we will have a release :) |
I've checked the error on the current Fixed by #214 Closing the issue. In case the error remains after the next release, feel free to re-open. |
Hey @IlyaFaer, the customer is facing the following issues, can you look into them: The first one is, it seems not to be able to pick up the sqlalchemy-spanner dialect unless I change the database URL from something like this: "spanner:///projects/project-id/instances/instance-id/databases/database-id" so, specifying the driver like that fixed the first issue. SQLALCHEMY_DATABASE_URI = f"mysql+pymysql://{PRIMA_DB_USERNAME}:{PRIMA_DB_PASSWORD}@{PRIMA_PROC_DB_HOST}/prima_processing" The second one is similar to the initial error (not the above one), but this time I get it every time I make a mysql related query it throws this error. [2022-06-08 10:59:13,949] ERROR in base: Exception during reset or similar |
But, wait, when you create a connection to a Spanner database, SQLAlchemy uses our dialect for all the operations. It's not possible to use this dialect with MySQL, because Spanner and MySQL are different. If I understand your case correctly, you should use two different connections for two different databases - one for Spanner, another one for MySQL. By looking at the database URL prefixes, SQLAlchemy will understand what kind of a connection and dialect should be used. But it must be two separate connections/engines/dialects. I can add a condition into the reset mechanism not to do anything with no-Spanner connections, but I don't think it'll allow to run MySQL queries on Spanner dialect. |
Apologies for the late response. @IlyaFaer that make sense. It seems the changes made in this fork and this change both can fix the issue I was having even though I’m using a single engine for both Spanner and MySQL (Thank you for that). |
@amha19, if you'll do something like this: engine = create_engine( "spanner+spanner:///...")
engine2 = create_engine("mysql+mysql:///...") Engines and connections will be separate (and it's what Flask is doing, as far as I can tell). But all the connections will be using the same reset mechanism. That was the problem of the original issue - connections reset mechanism is global for all the engines and connections on your machine - that's something we didn't expect. Thus, if I understand correctly what you mean, it's already working like this. Connections are separate, it's the connections reset mechanism which brings confusion because of its globality (but from now on this mechanism first checks what kind of a connection it got before doing the actual reset). |
Environment details
uname -a 5.11.0-46-generic #51~20.04.1-Ubuntu
Steps to reproduce
Running this script:
ends up running the query, but also throwing an error -- output from the CLI:
Now, if I use:
it's all good. Any idea?
The text was updated successfully, but these errors were encountered: