Re: [sqlalchemy] sqlalchemy.orm.exc.FlushError on subclass

2023-09-06 Thread Mike Bayer
if you can't correct this model to apply the persistence details to the concrete class you wish to persist and query, then you'd do the suggested "enable_typechecks=False". There is no attribute in SQLAlchemy named "meta" and no stack trace is given here so I dont know to what that refers.

[sqlalchemy] sqlalchemy.orm.exc.FlushError on subclass

2023-09-06 Thread 'Luna Lucadou' via sqlalchemy
The project I am working on is split up into several modules. Previously, each module had its own ORM classes. However, due to several bugs arising from forgetting to update each module's ORM classes in lock step when adding new functionality, we have decided it would be best to extract the ORM

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-06 Thread Mike Bayer
it can be related to the driver or the "cloud" database you're using, we have lots of reports of SQL Server drivers not reporting on matched rows correctly On Wed, Sep 6, 2023, at 7:40 AM, Leandro Lázaro wrote: > I updated the driver to the latest version and removed the line >

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-06 Thread Mike Bayer
changing it to false means if an UPDATE statement that expects to update on primary key in the ORM does not actually match any rows, the program continues and this may be a silent failure, leading to more confusing problems later if the row was in fact deleted or is otherwise non-existent. On

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-06 Thread Leandro Lázaro
I updated the driver to the latest version and removed the line 'self.engine.dialect.supports_sane_rowcount = False,' and the same error occurred again. Could this driver also have an unknown bug? TCLOUD_DATABASE_DRIVER_V18 = "/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.1.1"

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-05 Thread Leandro Lázaro
It worked!!! Thank you very much, it solved my problem. I was already going crazy haha. I will try to update the driver to solve the problem right at the root. Just a doubt: Changing to false does not generate any side effects? Em ter., 5 de set. de 2023 às 21:16, Mike Bayer <

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-05 Thread Mike Bayer
we will work around what is likely some kind of driver related error: engine = create_engine(" your engine string normally .. ") engine.dialect.supports_sane_rowcount = False then run the program normally. the UPDATE will succeed. however, after the program runs, look in the database

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-09-05 Thread Leandro Lázaro
Hello, apologies for the delay. I'm using SQL Server. Updates using the code below work normally. However, when I try to change the object directly and apply commit, I receive the mentioned error. stmt = update(PPESSOA).where(PPESSOA.CODIGO ==

Re: [sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-03 Thread Mike Bayer
if the two values are the same, then it will report zero rows matched. re: "very small difference" the MySQL field is likely not storing the microseconds portion of the timestamp so if you run several operations in succession the timestamps are very likely identical. On Sat, Sep 2, 2023, at

Re: [sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-02 Thread Dumitru Gîra
Okay, I guess I figured out why this happens. We are using the mysql+mysqldb dialect and we were explicitly setting* 'client_flag': 0* which by default is set to 2 in SQLAlchemy, thus disabling CLIENT_FLAGS.FOUND_ROWS. Removing *'client_flag': 0 *or setting it to *'client_flag': 2 *makes

Re: [sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-01 Thread Mike Bayer
unless the row is being deleted, this would possibly be a driver bug. the pymysql driver should work pretty well whereas mysql-connector I would stay away from.I would need more detail to reproduce beyond that, the SQL statement has nohting wrong with it. On Fri, Sep 1, 2023, at 12:09 PM,

Re: [sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-01 Thread Dumitru Gîra
Hi Mike, thanks for the quick response. These would be the debug logs for import requests for i in range(2): r = requests.put('http://0.0.0.0:8080/update-datetime') print(r.text, r.code) 2023-09-01 16:06:20,711 INFO sqlalchemy.engine.Engine SELECT DATABASE() 2023-09-01 16:06:20,711 INFO

Re: [sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-01 Thread Mike Bayer
a stale data error with date/time fields is usually a mismatch between the date/time value you have locally and the one that's in the database,. assuming you are using the datetime column as a "version_id" in your mapping. Issues like strings vs. datetimes and/or microseconds portions being

[sqlalchemy] StaleDataError on UPDATE for a DATETIME field on multiple consecutive requests

2023-09-01 Thread Dumitru Gîra
I have encountered a very strange behaviour and I don't know where to look further. I have a small API https://pastebin.com/qW01jNz8 with 2 endpoints: one to update the name (VARCHAR) and one to update the last_login (DATETIME). If I make 10 consecutive requests to /update-string - everything

[sqlalchemy] OperationalError

2023-08-30 Thread RedFire
OperationalError sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "dev.wiilink24.com" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgresql" (Background on this error at: https://sqlalche.me/e/20/e3q8) Traceback (most

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-24 Thread Mike Graziano
Hi Simon, Thanks for responding to my post. It turns out that MyBatis can do exactly what you are saying which essentially sounds like a bulk ETL process. Again, the key difference is that MyBatis doesn’t require that the mapping be done with all the DB-specific definitions which I

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-23 Thread Simon King
My perspective: the SQLAlchemy ORM really comes into its own when you are making use of its Unit of Work system to load a batch of objects from the database, manipulate those objects, and then flush your changes back to the database. If you are only *loading* data then you don't need a lot of the

Re: [sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-08-22 Thread Mike Bayer
if it's fully reproducible every time with both statements, then this suggests something is happening with the database server itself, such as some kind of issue with triggers getting involved or something. In particular if this is MS SQL Server and there are triggers involved, the updated

[sqlalchemy] sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'PPESSOA' expected to update 1 row(s); 0 were matched.

2023-08-22 Thread Leandro Lázaro
Hello First, thanks for building this library. God bless you I've been trying to understand what's going on for days. This code works fine: https://pastebin.com/fLTnB8jy But if I try to modify any other parameter like PERSONAL EMAIL I get the error: sqlalchemy.orm.exc.StaleDataError:

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-21 Thread Mike Graziano
Hi Mike, Thanks for that info. It was just what I needed. I also want to thank you for your YouTube tutorials on SQLAlchemy. They are fantastic. I don’t want to make this a huge post, but I have a real pet peeve concerning ORMs. I come from a Java background where I used MyBatis as

Re: Migrate alembic_version table from Public to tenant schema

2023-08-20 Thread jens.t...@gmail.com
Thank you Brian and Mike, just the conversation I was looking for. One follow-up question — is this a one-time step, and can I point all subsequently generated/applied migrations to the new schema and version_table? I think, Brian, your question regards a permanent migration of the table

Re: [sqlalchemy] Queue Pool Error

2023-08-18 Thread Mike Bayer
SQLAlchemy docs have a whole section on what this error means at: https://docs.sqlalchemy.org/en/20/errors.html#queuepool-limit-of-size-x-overflow-y-reached-connection-timed-out-timeout-z On Fri, Aug 18, 2023, at 2:34 AM, Krishnendu Ghosh wrote: > *queue pool limit of size 5 overflow 10

[sqlalchemy] Queue Pool Error

2023-08-18 Thread Krishnendu Ghosh
*queue pool limit of size 5 overflow 10 reached connection timed out timeout 30.00* how to solve in python flask_sqlalchemy for gcp cloud sql ? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE:

Re: [sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-17 Thread Mike Bayer
the raw SQL to ORM mapping pattern has a lot of limitations but it is documented at https://docs.sqlalchemy.org/en/20/orm/queryguide/select.html#getting-orm-results-from-textual-statements . On Thu, Aug 17, 2023, at 4:26 PM, Mike Graziano wrote: > To all, > > I am new to Python and

[sqlalchemy] Issuing Raw SQL and Returning a List of Objects

2023-08-17 Thread Mike Graziano
To all, I am new to Python and SQLAlchemy. I was a Java developer who used the MyBatis ORM. I was using PONY ORM for a while, but was concerned that SQLAlchemy is the gold standard for ORMs and Python, but there is something about MyBatis that I can't seem to find in SQLAlchemy, but maybe I

Re: [sqlalchemy] Dogpile session caching

2023-08-02 Thread Mike Bayer
I will note, in case you didn't see it, that in SQLAlchemy 1.4 (as well as in 2.0) the caching mechanics themselves have changed compared to what they were in SQLAlchemy 1.3. This change was first made in the 1.4 series to use the new do_orm_execute() event model, whereas previously in 1.3

Re: [sqlalchemy] Dogpile session caching

2023-08-02 Thread Mike Bayer
I've just updated them to use new style queries. There were no issues and all the examples work by switching `Session.query(Thing)` for `Session.scalars(select(Thing))`. The examples will be on the site within an hour but you can see the changes made in

[sqlalchemy] Dogpile session caching

2023-08-02 Thread 'Joe Black' via sqlalchemy
Hello, First of all, excellent project! It's such a powerful tool when you really master the internals, and after several years I think I'm nearing that point. My question today is related to the dogpile caching example

Re: [sqlalchemy] Sqlacodegen freeze when generate models.py

2023-08-01 Thread Mike Bayer
hi - sqlacodegen issues should be discussed at https://github.com/agronholm/sqlacodegen/discussions/categories/q-a On Tue, Aug 1, 2023, at 7:57 AM, Leandro Lázaro wrote: > Hello, > When I use the command sqlacodegen mssql+pymssql://USER:PASS@IP:PORT/DB > > model.py, the process hangs and

[sqlalchemy] Sqlacodegen freeze when generate models.py

2023-08-01 Thread Leandro Lázaro
Hello, When I use the command sqlacodegen mssql+pymssql://USER:PASS@IP:PORT/DB > model.py, the process hangs and continues running for several hours without any results. The database I'm trying to generate models.py for is quite large (over 1000 tables). Is the execution time normal, or is

Re: [sqlalchemy] Seeking experience/suggestions regarding connection pools

2023-07-13 Thread Mike Bayer
On Thu, Jul 13, 2023, at 8:07 PM, jens.t...@gmail.com wrote: > Hello, > > The SQLA Pooling section > says that the default > connection pool (QueuePool is the default pool, isn’t it?) has 5 connections > with an overflow of 10 (docs >

[sqlalchemy] Seeking experience/suggestions regarding connection pools

2023-07-13 Thread jens.t...@gmail.com
Hello, The SQLA Pooling section says that the default connection pool (QueuePool is the default pool, isn’t it?) has 5 connections with an overflow of 10 (docs

[sqlalchemy] Re: session.close() is not wokring sqlalchemy i have tried diffrent diffrent way but it's not working i am trying sqlalchemy session in python but it's not working still getting session a

2023-07-07 Thread Jonathan Vanasco
That is working as intended. `close()` just resets the session and connection, returning it to a connection pool to be used again. https://docs.sqlalchemy.org/en/20/orm/session_basics.html#closing The Session.close()

[sqlalchemy] session.close() is not wokring sqlalchemy i have tried diffrent diffrent way but it's not working i am trying sqlalchemy session in python but it's not working still getting session after

2023-07-07 Thread React Netive
from sqlalchemy import create_engine,text from sqlalchemy.orm import sessionmaker, declarative_base from datetime import datetime from sqlalchemy.orm import relationship from sqlalchemy import Column, ForeignKey, Integer, String, DateTime, Text, Boolean from sqlalchemy.orm import scoped_session

Re: [sqlalchemy] Usage of sqlalchemy Uuid type in declarative mapping

2023-07-06 Thread Pierre Massé
You are fing awesome Mike. Thanks for the answer and the links, I will dive into it tomorrow first thing in the morning. Le jeu. 6 juil. 2023 à 19:27, Mike Bayer < mike_not_on_goo...@zzzcomputing.com> a écrit : > > > On Thu, Jul 6, 2023, at 1:21 PM, Pierre Massé wrote: > > Dear all, > > I

Re: [sqlalchemy] Usage of sqlalchemy Uuid type in declarative mapping

2023-07-06 Thread Mike Bayer
On Thu, Jul 6, 2023, at 1:21 PM, Pierre Massé wrote: > Dear all, > > I am currently working on implementing UUID as primary keys in my database. > > I have come across an issue that I cannot find an explanation for: using the > `sqlalchemy.Uuid` type in declarative mapping yields different

[sqlalchemy] Usage of sqlalchemy Uuid type in declarative mapping

2023-07-06 Thread Pierre Massé
Dear all, I am currently working on implementing UUID as primary keys in my database. I have come across an issue that I cannot find an explanation for: using the `sqlalchemy.Uuid` type in declarative mapping yields different results at initialization. I sometimes get the following error: *"The

Re: [sqlalchemy] Left join and nested inner join

2023-07-05 Thread Michael Ekoka
Thanks, it worked. On Monday, July 3, 2023 at 8:49:58 PM UTC+7 Mike Bayer wrote: > use the join construct directly > > from sqlalchemy.orm import join > > > stmt = select(A).outerjoin(join(B, C), A.id == B.a_id) > > > > On Mon, Jul 3, 2023, at 8:29 AM, Michael Ekoka wrote: > > > Hi, I'm looking

Re: [sqlalchemy] Should I use a surrogate primary key on an Association Object pattern?

2023-07-04 Thread Pierre Massé
Thanks a lot Micheal. It was the way I was leaning forward to - but having confirmation from a long time user made me take the decision. Have a nice day ! Pierre Le lun. 3 juil. 2023 à 22:54, 'Michael Mulqueen' via sqlalchemy < sqlalchemy@googlegroups.com> a écrit : > Hi Pierre, > > This

Re: [sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Andrew Martin
This is awesome! Thank you, Mike! -andrew On Monday, July 3, 2023 at 11:05:28 PM UTC-5 Mike Bayer wrote: > this is a major area of functionality that begins with the > "with_loader_criteria" feature: >

Re: [sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Mike Bayer
this is a major area of functionality that begins with the "with_loader_criteria" feature: https://docs.sqlalchemy.org/en/20/orm/queryguide/api.html#sqlalchemy.orm.with_loader_criteria integration to make the criteria automatic follows at

[sqlalchemy] Soft Delete Pattern

2023-07-03 Thread Andrew Martin
Hello, I have a base class I tend to use that includes a Boolean is_deleted field so that pretty much every object has that available. Is there a good pattern for setting a filter on these objects that automatically adds a WHERE is_deleted = 'false'? Or does that just have to be added as a

Re: [sqlalchemy] Should I use a surrogate primary key on an Association Object pattern?

2023-07-03 Thread 'Michael Mulqueen' via sqlalchemy
Hi Pierre, This isn't an official answer, I'm just a long time user of SQLAlchemy. Either way should work fine. The association object is driven by the columns on the association table being FKs, whether or not they're part of a PK isn't relevant. I've used both ways. In my experience, an

[sqlalchemy] Should I use a surrogate primary key on an Association Object pattern?

2023-07-03 Thread Pierre Massé
Dear all, I am currently reworking a bit of my model and stumbled into this question, which I think mainly has opinionated answers - but I would like to have some insight regarding SQLAlchemy usage or preferences. I have a situation where I am in the exact same case like the one described in the

Re: [sqlalchemy] Left join and nested inner join

2023-07-03 Thread Mike Bayer
use the join construct directly from sqlalchemy.orm import join stmt = select(A).outerjoin(join(B, C), A.id == B.a_id) On Mon, Jul 3, 2023, at 8:29 AM, Michael Ekoka wrote: > > Hi, I'm looking for the SQLAlchemy equivalent to the query > > SELECT * > FROM a > LEFT OUTER JOIN (b INNER JOIN

[sqlalchemy] Left join and nested inner join

2023-07-03 Thread Michael Ekoka
Hi, I'm looking for the SQLAlchemy equivalent to the query SELECT * FROM a LEFT OUTER JOIN (b INNER JOIN c ON b.id = c.b_id) ON a.id = b.a_id Related: https://stackoverflow.com/a/56815807/56974 https://stackoverflow.com/questions/25514160/nested-joins-in-sqlalchemy Table "b" and "c" are

Re: [sqlalchemy] orm.column_property()

2023-06-23 Thread Mike Bayer
On Fri, Jun 23, 2023, at 9:38 AM, Julien Cigar wrote: > On Fri, Jun 23, 2023 at 09:29:27AM -0400, Mike Bayer wrote: >> >> Hi Julien - > > Hi Mike, > >> >> OK, if we're going to do one of your big queries, can we please start fresh, >> make a new discussion at >>

Re: [sqlalchemy] orm.column_property()

2023-06-23 Thread Julien Cigar
On Fri, Jun 23, 2023 at 09:29:27AM -0400, Mike Bayer wrote: > > Hi Julien - Hi Mike, > > OK, if we're going to do one of your big queries, can we please start fresh, > make a new discussion at https://github.com/sqlalchemy/sqlalchemy/discussions > , give me **really really succinct** models

Re: [sqlalchemy] Problems with multiple consecutive joins

2023-06-23 Thread Mike Bayer
hi - same as the other message I just answered here, nobody can tell what would be wrong with this query without a runnable example, please post **very succinct** sample classes + the query you are seeking at https://github.com/sqlalchemy/sqlalchemy/discussions On Fri, Jun 23, 2023, at 6:10

Re: [sqlalchemy] orm.column_property()

2023-06-23 Thread Mike Bayer
Hi Julien - OK, if we're going to do one of your big queries, can we please start fresh, make a new discussion at https://github.com/sqlalchemy/sqlalchemy/discussions , give me **really really succinct** models + the query you want, etc. the google groups thing here is not exactly going

Re: [sqlalchemy] orm.column_property()

2023-06-23 Thread Julien Cigar
On Fri, Jun 23, 2023 at 10:48:27AM +0200, Julien Cigar wrote: > > On Wed, Jun 21, 2023 at 08:35:36AM -0400, Mike Bayer wrote: > > > > > > > > On Wed, Jun 21, 2023, at 5:12 AM, Julien Cigar wrote: > > > Hello, > > > > > > I'm trying to add a column_property to recursively load and merge some >

[sqlalchemy] Problems with multiple consecutive joins

2023-06-23 Thread Piotr
I have a problems with a CTE query using multiple consecutive joins (A -> B -> C -> D). A and B have both relation to other table so they are joined by that other_id value. C has FK to B and C-D are One to One (id=id). The query looks like so: latest_message = (session.query(

Re: [sqlalchemy] orm.column_property()

2023-06-23 Thread Julien Cigar
On Wed, Jun 21, 2023 at 08:35:36AM -0400, Mike Bayer wrote: > > > > On Wed, Jun 21, 2023, at 5:12 AM, Julien Cigar wrote: > > Hello, > > > > I'm trying to add a column_property to recursively load and merge some > > json column. > > > > I have the following: > >

Re: [sqlalchemy] Error: Packet sequence number wrong for read replica

2023-06-22 Thread Federico Caselli
Hi, > It seems SQLAlchemy uses the same session for all request because session is created with same way we did in SQLAlchemy instance no it creates a single *scoped* session, but that uses a thread local variable to have a different session for each thread. Also I think flask sqlalchemy

Re: [sqlalchemy] Getting a triple of related id fields

2023-06-21 Thread Mike Bayer
they are perfectly fine to use, nothing is going away with any of that, so take any amount of time to migrate them (or not). On Wed, Jun 21, 2023, at 1:58 PM, Dan Stromberg wrote: > On Tue, Jun 20, 2023 at 3:47 PM Mike Bayer > wrote: >> >> >> step 1 is stop using that silly Flask extension

Re: [sqlalchemy] Getting a triple of related id fields

2023-06-21 Thread Dan Stromberg
On Tue, Jun 20, 2023 at 3:47 PM Mike Bayer wrote: > > > step 1 is stop using that silly Flask extension that gives you > "Pipeline.query", I can't tell what it is you want to SELECT from either by > reading this query. Wow, that made things a lot easier. Is there any reason to avoid mixing

Re: [sqlalchemy] orm.column_property()

2023-06-21 Thread Mike Bayer
On Wed, Jun 21, 2023, at 5:12 AM, Julien Cigar wrote: > Hello, > > I'm trying to add a column_property to recursively load and merge some > json column. > > I have the following: > https://gist.github.com/silenius/1af1072abae5829f54584f1ea554e074 but I > cannot figure how can I replace the

[sqlalchemy] Error: Packet sequence number wrong for read replica

2023-06-21 Thread Ali Hopyar
0 We have an environment with the following libraries and versions; Python 3.8 Flask 1.0.2 Flask-SQLAlchemy 2.3.0 SQLAlchemy 1.2.10 PyMySQL 1.0.2 Normally, we run on a single RDS Mysql but because of the high load we needed to add a read

[sqlalchemy] orm.column_property()

2023-06-21 Thread Julien Cigar
Hello, I'm trying to add a column_property to recursively load and merge some json column. I have the following: https://gist.github.com/silenius/1af1072abae5829f54584f1ea554e074 but I cannot figure how can I replace the '5011' at line 11 (which is the object primary key) with the "current"

Re: [sqlalchemy] Getting a triple of related id fields

2023-06-20 Thread Mike Bayer
step 1 is stop using that silly Flask extension that gives you "Pipeline.query", I can't tell what it is you want to SELECT from either by reading this query. looks like you have pipeline_alias1 and pipeline_alias2, but you are selecting from plain Pipeline, nothing is joining to it however.

[sqlalchemy] Getting a triple of related id fields

2023-06-20 Thread Dan Stromberg
I've been banging on this for hours, but I seem to be getting nowhere. I've tried more things that I can count, but here are two of my attempts: # result = ( #Pipeline.query # .select_from(Storage, NewProduct) # .join(Storage, pipeline_alias1.storage_id == Storage.id) #

Re: [sqlalchemy] double entries w/ logger config file (echo was set to False, now True after logging configured)

2023-06-17 Thread Dmitry Mugtasimov
See https://stackoverflow.com/a/76498428/1952977 On Monday, May 10, 2010 at 8:05:40 AM UTC+4 Michael Bayer wrote: > The issue is that you have configured two handlers by setting > handler=consoleHandler in two places, it should only be on "root" typically. > > engine.echo uses Python logging

Re: [sqlalchemy] double entries w/ logger config file (echo was set to False, now True after logging configured)

2023-06-17 Thread Dmitry Mugtasimov
See https://stackoverflow.com/a/76498428/1952977 On Monday, May 10, 2010 at 8:05:40 AM UTC+4 Michael Bayer wrote: > The issue is that you have configured two handlers by setting > handler=consoleHandler in two places, it should only be on "root" typically. > > engine.echo uses Python logging

Re: [sqlalchemy] Turning a complex query into a view for SQLAlchemy?

2023-06-16 Thread Mike Bayer
SQLAlchemy has no intrinsic issue with views but the thing that goes wrong with views is that they perform very poorly when used with composition. that is, if you take your view and use in a subquery, do some GROUP BY on it, do some LEFT OUTER JOIN onto it, the performance plummets, because

[sqlalchemy] Turning a complex query into a view for SQLAlchemy?

2023-06-16 Thread Dan Stromberg
Hi. In https://pajhome.org.uk/blog/10_reasons_to_love_sqlalchemy.html it says: When performing highly complex queries, it is possible to define these with SQLAlchemy syntax. However, I find there's a certain level of complexity where it becomes easier to write SQL directly. In that case, you can

Re: [sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Mike Bayer
On Mon, Jun 12, 2023, at 3:12 AM, Lele Gaifax wrote: > Lele Gaifax writes: > >> I will study the contains_eager() alternative and try to modernize my >> code that still uses that idiom. > > After reading the different sections (narrative and reference), I wonder > if there is a case where the

[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Lele Gaifax
Lele Gaifax writes: > I will study the contains_eager() alternative and try to modernize my > code that still uses that idiom. After reading the different sections (narrative and reference), I wonder if there is a case where the joinedload() has some advantage over contains_eager(), or if the

[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-12 Thread Lele Gaifax
Federico Caselli writes: > Also you may not need the col_by_name at all for order_by, since you can > pass the string in order_by directly: > https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#tutorial-order-by-label > This case is still not supported, since doing

[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-11 Thread Federico Caselli
Also you may not need the col_by_name at all for order_by, since you can pass the string in order_by directly: https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#tutorial-order-by-label This case is still not supported, since doing "query.order_by('firstname')" raises "column not

[sqlalchemy] Re: Trying to find a way to sort a query given the name of one of its columns

2023-06-10 Thread Lele Gaifax
"Mike Bayer" writes: > it looks like you're trying to add an ORDER BY to the table that's > only there via joinedload(). That's *really* not something we > anticipate and it would be better if people proposed perhaps ad-hoc > order_by expressions to be added to common loader options like >

Re: [sqlalchemy] Trying to find a way to sort a query given the name of one of its columns

2023-06-10 Thread Mike Bayer
it looks like you're trying to add an ORDER BY to the table that's only there via joinedload().That's *really* not something we anticipate and it would be better if people proposed perhaps ad-hoc order_by expressions to be added to common loader options like joinedload() and selectinload(),

[sqlalchemy] Trying to find a way to sort a query given the name of one of its columns

2023-06-10 Thread Lele Gaifax
Hi, I spent some more time to improve support for SA 2 of one of my SA-based libraries[1] (the most ancient one, born with SA 0.5, fifteen years ago!): its goal is to provide a layer that made it easier to "expose" a SA query (either an ORM one or a Core select()) thru a web service, handling

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Mike Bayer
On Thu, Jun 8, 2023, at 12:47 PM, Suraj Shaw wrote: > Hi Mike, > > One more update. > I am using DRCP functionality of oracle so i have to add :pooled at the end > of connect string. > If you run without using :pooled it is running correctly with output as > (datetime.datetime(2023, 6, 8, 22,

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Mike Bayer
On Thu, Jun 8, 2023, at 12:38 PM, Suraj Shaw wrote: > Hi Mike, > > Is it like first conn.close() is closing the pool itself instead of releasing > connection back to pool. SQLAlchemy calls the .close() method on the connection itself. Per oracledb docs at

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Suraj Shaw
Hi Mike, One more update. I am using DRCP functionality of oracle so i have to add :pooled at the end of connect string. If you run without using :pooled it is running correctly with output as (datetime.datetime(2023, 6, 8, 22, 13, 56, 762291),) (datetime.datetime(2023, 6, 8, 22, 13, 57,

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Suraj Shaw
Hi Mike, Is it like first conn.close() is closing the pool itself instead of releasing connection back to pool. Thanks Suraj On Thu, 8 Jun 2023 at 18:34, Mike Bayer wrote: > unknown. I've run your program exactly as written with SQLAlchemy 2.0.15 > and it succeeds on both queries. I would

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Mike Bayer
unknown. I've run your program exactly as written with SQLAlchemy 2.0.15 and it succeeds on both queries. I would advise reaching out to https://github.com/oracle/python-oracledb/discussions for debugging help. feel free to show them our recipe from

Re: [sqlalchemy] Sql constructor

2023-06-08 Thread Mike Bayer
we can't take on maintenance for new extensions within the SQLAlchemy project directly but I would encourage you to release your extension as its own library; see https://pypi.org/search/?q=sqlalchemy for other examples On Tue, Jun 6, 2023, at 5:34 PM, Nir Assaraf wrote: > Hey guys, > > As a

[sqlalchemy] connection pooling

2023-06-08 Thread Suraj Shaw
Hi Team, I am using connection pooling in sqlalchemy using oracle own pool.My script looks like this. ``` from sqlalchemy import create_engine,text from sqlalchemy.pool import NullPool import oracledb pool = oracledb.create_pool(user='XXX', password='XXX',dsn='XXX:1521/XXX', min=1, max=5,

[sqlalchemy] Sql constructor

2023-06-06 Thread Nir Assaraf
Hey guys, As a part of a project that I'm working on, Iv'e created a SQLAlchemy statement builder using the ast (abstract syntax trees) library. This constructor will parse strings that are valid python logical statements and will convert them to the appropriate SQLAlchemy objects. For

Re: [sqlalchemy] subquery relationships?

2023-05-31 Thread Mike Bayer
docs for this are at: https://docs.sqlalchemy.org/en/20/orm/join_conditions.html there are several approaches to relationships with subqueries, the most open ended is the one described at https://docs.sqlalchemy.org/en/20/orm/join_conditions.html#relationship-to-aliased-class On Wed, May

[sqlalchemy] subquery relationships?

2023-05-31 Thread Dan Stromberg
Hi folks. I have a subquery that is selected from a table with 5 foreign keys, and joined with another table with 3 foreign keys. And then that subquery is used in a join with the table having the 3 foreign keys again. I don't know how to tell what column(s) that join is happening on. What

Re: [sqlalchemy] Interpreting a SA traceback

2023-05-24 Thread Philip Semanchuk
> On May 24, 2023, at 1:33 PM, Dan Stromberg wrote: > > I know, python2 is long dead. We’re almost ready for Python3, but not quite. > > Anyway, here’s a traceback that I’m not sure what to make of. Is it > saying that a transaction got so big that it couldn’t be fully flushed > within the

[sqlalchemy] Interpreting a SA traceback

2023-05-24 Thread Dan Stromberg
I know, python2 is long dead. We’re almost ready for Python3, but not quite. Anyway, here’s a traceback that I’m not sure what to make of. Is it saying that a transaction got so big that it couldn’t be fully flushed within the timeout window? I’ve elided a sensitive part from the very end of

Re: [sqlalchemy] sqlalchemy returns None for sqlite tables which already have data

2023-05-22 Thread Mike Bayer
like someone mentioned there, showing the classes doesn't say much.I'd check that the table name is correct and definitely matches what's in the SQLite database that you are actually accessing, as well as that the primary key column in those tables is actually a primary key, or at least not

[sqlalchemy] sqlalchemy returns None for sqlite tables which already have data

2023-05-22 Thread m7mđ ĕğý
Hello mates, As my last msg had a so bad format i will keep the link of my original question on stackoverflow : https://stackoverflow.com/questions/76304295/sqlalchemy-returns-none-for-sqlite-tables-which-already-have-data i hope i get answers from you mates. Thanks -- SQLAlchemy -

[sqlalchemy] sqlalchemy returns None for sqlite tables which already have data

2023-05-22 Thread m7mđ ĕğý
there is something wrong with those two sqlite tables: select method returns none but the table already have data. is that because product class is Primary key and a foreign key at the same time? - i use sqlalchemy - those two tables returns none every time i try to query them. -

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-15 Thread Mike Bayer
On Mon, May 15, 2023, at 1:28 PM, Benjamin Taub wrote: > Hey, Mike! > I just wanted to let you know I figured this out. Your sample code led me to > something I hadn't considered. After the routine I was stuck in, I take the > SQLAlchemy-generated code, turn it into a string, and add some >

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-15 Thread Benjamin Taub
Hey, Mike! I just wanted to let you know I figured this out. Your sample code led me to something I hadn't considered. After the routine I was stuck in, I take the SQLAlchemy-generated code, turn it into a string, and add some manually-generated SQL. I used a command like *str(SQL)* to get this

Re: [sqlalchemy] An Attribute Error is occurring but I am not understanding why?

2023-05-15 Thread Nishant Varma
Is it a JSON data type? I see some threads like this: https://github.com/sqlalchemy/sqlalchemy/issues/4027 On Mon, 15 May 2023 at 11:44, Shashank wrote: > I've created a flask application that makes use of SQLAlchemy to store and > retrieve the data, but I am facing this error. Can anybody

[sqlalchemy] An Attribute Error is occurring but I am not understanding why?

2023-05-15 Thread Shashank
I've created a flask application that makes use of SQLAlchemy to store and retrieve the data, but I am facing this error. Can anybody please specify why the error might be occurring and as to how to solve it. *File "/home/ubuntu/OCR/venv/lib/python3.7/site-packages/sqlalchemy/sql/sqltypes.py",

Re: [sqlalchemy] Migration issues - Column value None on select with joins

2023-05-14 Thread Mike Bayer
thanks! On Sun, May 14, 2023, at 6:59 PM, Shane Holcombe wrote: > I've tested all the ways I could previously trigger the issue and still, no > Nones seem to even be produced to be filtered out, that fix definitely seems > to have sorted the issue out > > On Sunday, May 14, 2023 at 7:42:54 AM

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-14 Thread Mike Bayer
On Sun, May 14, 2023, at 12:39 PM, Benjamin Taub wrote: > Hi, Mike! > I tried your code, and it worked after I set the dialect to mysql+pymysql. > > Given this, in my case, I believe the problem stems from the fact that I am > starting with a generic SELECT call that isn't moored to a dialect.

Re: [sqlalchemy] Migration issues - Column value None on select with joins

2023-05-14 Thread Shane Holcombe
I've tested all the ways I could previously trigger the issue and still, no Nones seem to even be produced to be filtered out, that fix definitely seems to have sorted the issue out On Sunday, May 14, 2023 at 7:42:54 AM UTC+10 Shane Holcombe wrote: > Yes so I'm testing the second solution with

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-14 Thread Benjamin Taub
Hi, Mike! I tried your code, and it worked after I set the dialect to mysql+pymysql. Given this, in my case, I believe the problem stems from the fact that I am starting with a generic SELECT call that isn't moored to a dialect. I start with *sql = select()* Which I have now changed

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-13 Thread Mike Bayer
On Sat, May 13, 2023, at 5:12 PM, Benjamin Taub wrote: > Thank you, Mike, but aren't I using the correct dialect with this > create_engine() command? > > *qry_engine = create_engine('mysql+pymysql://' + db_uid + ':' + db_pw > + '@' + db_addr, connect_args=connect_args, >

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-13 Thread Benjamin Taub
For what it's worth, I believe this double quoting issue is also happening with the .label() method of the column object (assuming that I do have the dialect appropriately set). The following code... *tbl_col = self.tbl.c[formula_col['table_column']].label(tmplt_col['name'])* Results in the

Re: [sqlalchemy] Migration issues - Column value None on select with joins

2023-05-13 Thread Shane Holcombe
Yes so I'm testing the second solution with a breakpoint on the area that should filter out those Nones, I wanted to see wether the Nones are being removed or are no longer showing up. So far I haven't seen that code be used, which is great, means the race condition thing must have helped. I

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-13 Thread Benjamin Taub
Thank you, Mike, but aren't I using the correct dialect with this create_engine() command? *qry_engine = create_engine('mysql+pymysql://' + db_uid + ':' + db_pw + '@' + db_addr, connect_args=connect_args, pool_recycle=3600, echo=False, future=True)*

Re: [sqlalchemy] Migration issues - Column value None on select with joins

2023-05-13 Thread Mike Bayer
the second solution has not only the removal of where the theoretical "race condition" might happen, but it also removes the "None" entries in any case, so even if the "None" thing is coming from somewhere else, they won't make it to the select() statement at the end. On Sat, May 13, 2023,

<    1   2   3   4   5   6   7   8   9   10   >