[sqlalchemy] test email

2023-11-22 Thread Mike Bayer
this is a test. -- 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

Re: [sqlalchemy] Composite columns and None

2023-11-15 Thread Mike Bayer
On Tue, Nov 14, 2023, at 6:02 PM, jens.t...@gmail.com wrote: > Hello everyone, > > I wanted to follow up on the examples on Composite Column Types > and in particular > setting the mapped composite value in Python-land to *None*. > >

Re: [sqlalchemy] sqlalchemy 2.0 and ABCMeta

2023-11-09 Thread Mike Bayer
hi - I'm not sure what the issue is but if you are tinkering with metaclasses, we first off have an alternate version of DeclarativeBase called DeclarativeBaseNoMeta that has no metaclass installed, and may be a better place to build off custom metaclass solutions as you wont need to be

Re: [sqlalchemy] Issue with type signature of DBAPI Connection

2023-11-07 Thread Mike Bayer
there does seem to be an extra Sequence on the outside that should be removed, please open an issue. On Tue, Nov 7, 2023, at 9:46 PM, William Hakim wrote: > I was recently using the DBAPI Cursor, and it seems to me that the type > signature of the `executemany()` function is incorrect: > >

Re: [sqlalchemy] Connection issue with URL-encoded passwords in `do-connect` event

2023-11-04 Thread Mike Bayer
On Fri, Nov 3, 2023, at 7:41 PM, SeJun Bae wrote: > Hello everyone, > I have encountered an odd behavior when using URL-encoded tokens as passwords > for connections with Postgres; my application connects to a Postgres AWS RDS > instance using a token that expires (IAM Authentication >

Re: [sqlalchemy] Postgresq Execute Many with Textual SQL Convenience Issue

2023-11-02 Thread Mike Bayer
On Thu, Nov 2, 2023, at 11:24 AM, mkmo...@gmail.com wrote: > Hi Mike, > > When using Core, we can do a bulk insert and bulk return with Postgresql > trivially: > > from sqlalchemy import table, column > t = table('foo', column('id'), column('bar') > > ins =

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-22 Thread Mike Bayer
to run > in tests. > > Thanks again for all the help, > Tony > > On Friday, October 20, 2023 at 11:10:23 PM UTC+8 Mike Bayer wrote: >> >> >> On Fri, Oct 20, 2023, at 10:46 AM, 'Tony Cosentini' via sqlalchemy wrote: >>> Oh I see, thanks for clarifying.

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread Mike Bayer
an object that just gets returned by a query from the identity map.you would need to do something more drastic like a do_orm_execute() hook that runs queries internally and then looks at all the returned objects. i wouldnt put that in production. > > Tony > > On Fri,

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread Mike Bayer
rash, but it never triggers. > > On Fri, Oct 20, 2023 at 9:20 PM Mike Bayer > wrote: >> __ >> >> >> On Fri, Oct 20, 2023, at 8:08 AM, 'Tony Cosentini' via sqlalchemy wrote: >>> Hi, >>> >>> Is there any way to listen for an event for

Re: [sqlalchemy] Event listener for when query results get matched with pre-existing objects on the session

2023-10-20 Thread Mike Bayer
On Fri, Oct 20, 2023, at 8:08 AM, 'Tony Cosentini' via sqlalchemy wrote: > Hi, > > Is there any way to listen for an event for when a query result gets merged > into a pre-existing object in the session? this is the refresh event:

Re: [sqlalchemy] Batch patch ORM entities

2023-10-11 Thread Mike Bayer
would strongly recommend. merge them with zip: for user, dist in zip(user_list, dist_df): user.dist = dist > > Regards, > > Pierre > > Le mer. 11 oct. 2023 à 15:07, Mike Bayer > a écrit : >> __ >> >> >> On Wed, Oct 11, 2023, at 4:22 AM,

Re: [sqlalchemy] Batch patch ORM entities

2023-10-11 Thread Mike Bayer
On Wed, Oct 11, 2023, at 4:22 AM, Pierre Massé wrote: > Dear all, > > I have a requirement that makes me think that I need to "mass patch" some ORM > objects. However, I am open to any suggestions regarding the way to answer my > requirements. > > I have defined an ORM object which

Re: [sqlalchemy] How to use IBM i Access ODBC Driver

2023-10-11 Thread Mike Bayer
SQLAlchemy does not include support for this driver - the only IBM driver is the ibm_db_sa you reference, so short of writing your own driver based on that one, that's what's available. On Tue, Oct 10, 2023, at 11:07 PM, Jack W. wrote: > I have the IBM i Access ODBC Driver >

Re: [sqlalchemy] why does sqlalchemy UUID succeed with mysql BINARY(16) but fails with postgres BYTEA

2023-10-11 Thread Mike Bayer
PostgreSQL has a native UUID datatype, so when you use SQLAlchemy's UUID, it maps to a real PG UUID datatype, not BYTEA. as for sqlalchemy_utils.UUIDType, we dont maintain that package here so you'd need to look at their source code. Overall if you want complete "UUID mapped to any arbitrary

Re: [sqlalchemy] sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'uuid_utils.UUID'

2023-10-02 Thread Mike Bayer
I havent read about uuid 7, however if it takes up the same number of bytes as other UUIDs, this "uuid_utils" should really be returning Python UUID objects and not something ad-hoc, that's the source of the incompatibility here. otherwise, you'd need to build a custom type, see

Re: [sqlalchemy] Issue DELETE statement with LIMIT

2023-09-22 Thread Mike Bayer
I thought we have a github for DELETE..LIMIT but we dont. This would be a construct specific to the MySQL dialect: from sqlalchemy.dialects.mysql import delete , where it would include order_by() and limit() params.We don't have internal resources to carry this through so we'd rely upon

Re: [sqlalchemy] Event: do_orm_execute inserted value

2023-09-20 Thread Mike Bayer
for a statement like that where the values are embedded in the insert() construct directly you would use: orm_execute_state.statement.compile().params this is mentioned in the tutorial at https://docs.sqlalchemy.org/en/20/tutorial/data_insert.html#the-insert-sql-expression-construct

Re: [sqlalchemy] Temporarily disable/intercept ORM events on mutation

2023-09-15 Thread Mike Bayer
On Fri, Sep 15, 2023, at 8:59 PM, Mike Bayer wrote: > > unfortunately no, that's a backref event handler, that's within the class > instrumentation and has no mechanism to be disabled on a per-class basis, not > to mention the backref handler is not the only aspect of things

Re: [sqlalchemy] Temporarily disable/intercept ORM events on mutation

2023-09-15 Thread Mike Bayer
On Fri, Sep 15, 2023, at 4:28 PM, 'Luna Lucadou' via sqlalchemy wrote: > When customers call our JSON:API API, they can use an "include" parameter to > specify related objects to be appended to the response. > > However, requests to include are not always satisfiable (e.g. if >

Re: [sqlalchemy] How to combine statement eager loading with polymorphic relations

2023-09-15 Thread Mike Bayer
() here. Was IO attempted in an unexpected place? (Background > on this error at: https://sqlalche.me/e/20/xd2s) > ``` > > With the help of raisedload(*) I get to see: > ``` > sqlalchemy.exc.InvalidRequestError: 'ServiceActionModel.service' is not > available due to lazy='raise```

Re: [sqlalchemy] How to combine statement eager loading with polymorphic relations

2023-09-14 Thread Mike Bayer
working on that issue but you should also be able to do this right now: .options( selectinload(StepModel.actionbases.of_type(ServiceActionModel)).selectinload(ServiceActionModel.service), raiseload("*"), ) that produces more of a LEFT OUTER JOIN with a subquery situation but still

Re: [sqlalchemy] How to combine statement eager loading with polymorphic relations

2023-09-14 Thread Mike Bayer
On Thu, Sep 14, 2023, at 7:36 AM, Cornelis Poppema wrote: > Hi all, > > I am new to sqlalchemy, I think the idea of what I am trying to achieve is > relatively simple, but I can't seem to figure out how to retrieve `.service` > in the same query. I failed to find an example in the 2.0

Re: [sqlalchemy] Unique constraint error in PostgrSQL when migrating with Alembic

2023-09-13 Thread Mike Bayer
your revisions table has a composite unique constraint - one constraint with two columns in it. therefore to refer to this constraint via foreign key, you need a single composite foreignkeyconstraint - again, one constraint that links two columns together. you would use ForeignKeyConstraint

Re: [sqlalchemy] Update Username and Password from vault

2023-09-08 Thread Mike Bayer
the engine is used. On Fri, Sep 8, 2023, at 12:13 PM, Steven Schierholz wrote: > Yes but only once when the app starts up. > > On Friday, September 8, 2023 at 10:04:45 AM UTC-6 Mike Bayer wrote: >> __ >> assuming proper indentation it looks fine. are your print stat

Re: [sqlalchemy] Update Username and Password from vault

2023-09-08 Thread Mike Bayer
with password: ", pg_password) > > cparams["user"] = pg_user > cparams["password"] = pg_password > > session_factory = sessionmaker(bind=engine) > sqla_session = session_factory() > > # Then using the sqla_session to execute queries an

Re: [sqlalchemy] Update Username and Password from vault

2023-09-07 Thread Mike Bayer
ol_recycle timeout is reached. On Thu, Sep 7, 2023, at 2:34 PM, Steven Schierholz wrote: > That makes sense but doesn't connect only happen once when create_engine() is > called? > > On Thursday, September 7, 2023 at 12:00:35 PM UTC-6 Mike Bayer wrote: >> __ >>

Re: [sqlalchemy] Update Username and Password from vault

2023-09-07 Thread Mike Bayer
the documentation for this pattern is at https://docs.sqlalchemy.org/en/20/core/engines.html#generating-dynamic-authentication-tokens , and a completely specific example is at https://docs.sqlalchemy.org/en/20/dialects/mssql.html#mssql-pyodbc-access-tokens . Basically your application needs

Re: [sqlalchemy] Duplicating a relationship from one ORM model to a subquery model

2023-09-07 Thread Mike Bayer
reate models that > inherit from an existing model, while loading/accessing only a subset of > columns (basically, polymorphism, without a polymorphism key)… Will gladly > take any suggestion on a different approach… > > But at least this seems to work! > > Thanks again, >

Re: [sqlalchemy] Duplicating a relationship from one ORM model to a subquery model

2023-09-07 Thread Mike Bayer
On Thu, Sep 7, 2023, at 4:39 AM, zedr...@gmail.com wrote: > > *Is there a clean way to (programmatically) duplicate all relationship from > an existing model, over to a new model (that targets the same table and > selects a subset of columns as a subquery)?* relatonships are fixed to their

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.

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
ed!!! 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

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
t; > Em ter., 5 de set. de 2023 às 21:16, Mike Bayer > escreveu: >> __ >> we will work around what is likely some kind of driver related error: >> >> engine = create_engine(" your engine string normally .. ") >> engine.dialect.supports_sane

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
BASE_NAME+'?driver='+TCLOUD_DATABASE_DRIVER > > Driver is: > > libmsodbcsql-17.10.so.4.1 > > Thank you for all! > > > > Em terça-feira, 22 de agosto de 2023 às 15:51:47 UTC-3, Mike Bayer escreveu: >> __ >> if it's fully reproducible every time with both statements, the

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

2023-09-03 Thread Mike Bayer
en the previous datetime/timestamp and the update > one? > > On Friday, September 1, 2023 at 10:23:56 PM UTC+3 Mike Bayer wrote: >> __ >> unless the row is being deleted, this would possibly be a driver bug. the >> pymysql driver should work pretty well whereas mysql-conn

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

2023-09-01 Thread Mike Bayer
l/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", > line 630, in execute > util.preloaded.orm_persistence.save_obj( > File > "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line > 237, in save_obj > _emit_update

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

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

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

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

Re: [sqlalchemy] Dogpile session caching

2023-08-02 Thread Mike Bayer
there was a Query subclass called CachingQuery or something like that. for 1.4 and above you would need to be using the do_orm_execute() code. On Wed, Aug 2, 2023, at 11:43 PM, Mike Bayer wrote: > I've just updated them to use new style queries. There were no issues and > all the example

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

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

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 >

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

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

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

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

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
away but it's an antiquated interface at this point. On Fri, Jun 23, 2023, at 4:48 AM, 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, >>

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 th

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

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.

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

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

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(),

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Mike Bayer
ocol.pyx", line 389, in > oracledb.thin_impl.Protocol._receive_packet > > File "src/oracledb/impl/thin/packet.pyx", line 559, in > oracledb.thin_impl.ReadBuffer.receive_packet > > File "src/oracledb/impl/thin/packet.pyx", line 358, in > oracledb

Re: [sqlalchemy] connection pooling

2023-06-08 Thread Mike Bayer
take here as of yet and you should post a discussion on the oracledb discussion tracker for assistance on what the error message you have actually means, since I dont know. > > Thanks > Suraj > > On Thu, 8 Jun 2023 at 18:34, Mike Bayer > wrote: >> __ >> unkn

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

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

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

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] Migration issues - Column value None on select with joins

2023-05-14 Thread Mike Bayer
ws up again but this seems much better, thank >> so much. >> >> On Sunday, May 14, 2023 at 2:37:37 AM UTC+10 Mike Bayer wrote: >>> __ >>> the second solution has not only the removal of where the theoretical "race >>> condition" might happen, but it also re

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-14 Thread Mike Bayer
is always given a dialect with which to compile with, and you can always pass this in. it's still not clear here if you are using .compile() directly or not as I dont really have an understanding of what you're doing. > > Thanks again for your help! > Ben > On Saturday, May 13, 2023

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-13 Thread Mike Bayer
previously, you should note that it generates backticks. > Thanks again! > Ben > On Friday, May 12, 2023 at 4:48:45 PM UTC-4 Mike Bayer wrote: >> >> >> On Fri, May 12, 2023, at 4:30 PM, Benjamin Taub wrote: >>> I have code that worked under SQLAlchemy 1.4 but r

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

2023-05-13 Thread Mike Bayer
n_user' model in the query I sent. > I'll test it again a few more times/ways later tonight/tomorrow morning when > I get a chance again and let you know > Thanks so much > On Saturday, May 13, 2023 at 1:50:56 PM UTC+10 Mike Bayer wrote: >> __ >> in the below mentioned issu

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

2023-05-12 Thread Mike Bayer
the None objects in any case.you'd want to take a look at that and see if it resolves. On Fri, May 12, 2023, at 11:30 PM, Mike Bayer wrote: > I've opened https://github.com/sqlalchemy/sqlalchemy/issues/9777 for this. > > I have another theory where something might be going wro

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

2023-05-12 Thread Mike Bayer
e columns but I'll try and > see what happens. > Thanks > On Saturday, May 13, 2023 at 12:59:33 PM UTC+10 Mike Bayer wrote: >> __ >> well, not sure yet how a None is coming in there that is sporadic, or even >> at all, but if that's what's happening then we would think th

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

2023-05-12 Thread Mike Bayer
that patch ? On Fri, May 12, 2023, at 10:47 PM, Mike Bayer wrote: > OK, maybe you are onto something with the theory re: > JoinedLoader._generate_row_adapter(). will look at that > > On Fri, May 12, 2023, at 6:16 PM, Shane Holcombe wrote: >> Thanks for linking that github issue,

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

2023-05-12 Thread Mike Bayer
joinedload(Lead.lu_lead_closed_state), > joinedload(Lead.lu_lead_lost_reason), > joinedload(Lead.lu_marketing_channel), > joinedload(Lead.lu_marketing_channel_digital), > joinedload(Lead.lu_marketing_channel_on_site), > joinedload(Lead.lu_marketing_channel_out_of_home), > joinedloa

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-12 Thread Mike Bayer
On Fri, May 12, 2023, at 4:30 PM, Benjamin Taub wrote: > I have code that worked under SQLAlchemy 1.4 but recently upgraded to 2. I am > using the add_columns() method to add columns to an existing SQL statement. > The resultant queries sometimes, but not always, crash. I believe the issue >

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

2023-05-12 Thread Mike Bayer
I really need to see: 1. actual models to the degree they illustrate the default loaders set up on relationships 2. query in use 3. **complete** stack trace, put it on a github gist if it's too long. every line, the error, top to bottom. thanks On Fri, May 12, 2023, at 11:25 AM, Mike Bayer

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

2023-05-12 Thread Mike Bayer
On Fri, May 12, 2023, at 1:25 AM, Shane Holcombe wrote: > AttributeError: 'NoneType' object has no attribute '_from_objects' > (I've shortened this from the entire traceback) OK what kind of traceback, is it a recursion overflow kind of traceback ? (e.g. many hundreds of repeated series of

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

2023-05-12 Thread Mike Bayer
this has also been reported at https://github.com/sqlalchemy/sqlalchemy/discussions/9666 On Fri, May 12, 2023, at 1:25 AM, Shane Holcombe wrote: > > From the digging around that I've done, it seems to be the ColumnLoader > strategy setup_query method sometimes has a value for 'c' of None

Re: [sqlalchemy] Transaction integrity issue in SQLAlchemy SQLite dialect

2023-05-10 Thread Mike Bayer
the pysqlite driver does not deliver SERIALIZABLE isolation in its default mode of use. you have to use workarounds to achieve this. See the documentation at https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#serializable-isolation-savepoints-transactional-ddl which details how to use

Re: [sqlalchemy] How to set Row instance attribute

2023-05-07 Thread Mike Bayer
On Sat, May 6, 2023, at 5:28 PM, sector119 wrote: > Hello, > > I get some data from DB and have a sequence of Row objects, how it is > possible to modify data in those objects attrs? you can't. copy them to something you can modify > > Something like > > result = await

Re: [sqlalchemy] DRYing up model relationships with custom properties

2023-05-03 Thread Mike Bayer
I'd be a little concerned about the double-underscore as it modifies the way Python getattr() works for those names, and I dont know that we have tests for that specific part of it, but besides that, you can always add new relationships or other mapped attributes to classes in one of two ways:

Re: [sqlalchemy] Exceeding the queue pool limit in a Flask application problem

2023-04-30 Thread Mike Bayer
are you making sure you create only one global OrmEngine object for the whole application? SQLA docs recommend engines are global On Fri, Apr 28, 2023, at 12:48 PM, Erabil Erabil wrote: > When using SQL Alchemy in a Flask application, if the application > continuously sends queries to the

Re: [sqlalchemy] StaleDataError on simple update statement

2023-04-26 Thread Mike Bayer
this can happen if you are using the wrong datatype for your primary key. like it's a string in the database and you are referring to it as an Integer, that kind of thing. no way to provide more detail without seeing a short version of the mapping that produces this error and CREATE TABLE

Re: [sqlalchemy] Modifying Query Object

2023-04-16 Thread Mike Bayer
if you add a column to a Query that was returning an object, like Data, you will get back tuples of (Data, extra_col). this is probably what the tool you are using is complaining about. On Fri, Apr 14, 2023, at 10:51 PM, Mike Bayer wrote: > > > On Tue, Apr 11, 2023, at 9:17 PM, Lui

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Mike Bayer
On Tue, Apr 11, 2023, at 9:17 PM, Luis Del Rio IV wrote: > The sql query itself returns several rows, as it should. But when trying to > combine the max using sqlalchemy the rows return as the following. > > Received incompatible instance \"( 0x7f2c6cfd6670>, '2021-04-10 18',

Re: [sqlalchemy] Re: Dealing with readonly column

2023-04-14 Thread Mike Bayer
On Fri, Apr 14, 2023, at 3:02 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > >> On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: >>> I now have >>> >>> CREATE TABLE something (id SERIAL, name TEXT) >>> >>> CREATE FUN

Re: [sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Mike Bayer
\ >.join(EstoqueEmpresa, and_(EstoqueEmpresa.IdProduto == > Produto.IdProduto, EstoqueEmpresa.DtReferencia == > estoqueAtual.c.MaxDtReferencia))\ >.filter(ProdutoEmpresa.StAtivoVenda == 'S')\ > .filter(ProdutoEmpresa.CdEmpresa == 4)\ >

Re: [sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Mike Bayer
the initial issue is that you want DtReferencia from the subquery on the outside: session.query(..., estoqueAtual.c.DtReferencia, ...) and not "EstoqueEmpresa.DtReferencia", that's not available in the FROM list, it's inside a subquery. also I dont think you'd want to "group by" the same

Re: [sqlalchemy] Dealing with readonly column

2023-04-14 Thread Mike Bayer
On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: > Hi, > > I wonder if there is a way to declare a particular column of a table as > "readonly", either for the purpose of documenting the model, or to get > early error should someone try to update it. "readonly" can mean a few different

Re: [sqlalchemy] Query object modification

2023-04-13 Thread Mike Bayer
On Thu, Apr 13, 2023, at 4:14 PM, Luis Del Rio IV wrote: > Mike, > > Would this select query be able to get our aggregated data? > > query = > select(func.max(DataModel.value)).select_from(_query.subquery()).group_by( > func.date_format(DataModel.timestamp, "%Y-%m-%d %H")

Re: [sqlalchemy] Query object modification

2023-04-13 Thread Mike Bayer
On Thu, Apr 13, 2023, at 1:13 PM, Peter Harrison wrote: > Thanks Mike, > > Ideally we'd prefer to find a solution via Graphene-SQLAlchemy. Unfortunately > we don't have the luxury of creating our own query when interacting with > Graphene-SQLAlchemy. > > So the key question for us is, can

Re: [sqlalchemy] Access other columns in a custom type

2023-04-13 Thread Mike Bayer
On Thu, Apr 13, 2023, at 6:10 AM, Hussein Samadi wrote: > Hi everyone. > I'm creating a new SQLA custom type using TypeDecorator base class. Is it > possible to have access to the value of other fields in > "process_result_value" method? Generally, is it possible to create a custom > type

Re: [sqlalchemy] Query object modification

2023-04-12 Thread Mike Bayer
On Wed, Apr 12, 2023, at 5:21 PM, Luis Del Rio IV wrote: > I am currently using the following sqlalchemy code, > > _query = super().get_query(model, info, sort, **args) > query = _query.group_by( > func.date_format(DataModel.timestamp, "%Y-%m-%d %H") > ) >

Re: [sqlalchemy] missing schema authorization clause

2023-04-05 Thread Mike Bayer
I've never heard of this concept before so a google into stack overflow shows https://stackoverflow.com/questions/10994414/missing-authorization-clause-while-creating-schema, where you are probably looking for: with engine.begin() as conn: conn.execute(text("create user {schema_name}

Re: [sqlalchemy] relationships between inheritance tables

2023-03-31 Thread Mike Bayer
this is not so much about the database models as it is about the queries being emitted and what kinds of data are being returned. I would go through the section at https://docs.sqlalchemy.org/en/20/faq/performance.html#how-can-i-profile-a-sqlalchemy-powered-application and identify where the

Re: [sqlalchemy] TLS 1.2

2023-03-28 Thread Mike Bayer
this is a driver issue so you'd need to get specifics from the driver you're using, such as mysqlclient or pymysql. per https://dev.mysql.com/doc/c-api/8.0/en/c-api-encrypted-connections.html it looks like "TLS_VERSION" create_engine("mysql+mysqldb://...?ssl=true", connect_args={"ssl":

Re: [sqlalchemy] How to use sqlcodegen generate SQLModels

2023-03-22 Thread Mike Bayer
hey there- sqlacodegen support is on their github at https://github.com/agronholm/sqlacodegen/discussions/categories/q-a On Wed, Mar 22, 2023, at 6:55 PM, Linson Abah wrote: > Hi, > I am trying to convert the schema of a db to SQLModels: I have this short > script: > > *from subprocess

Re: [sqlalchemy] Test query seems to spuriously give sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1054, "Unknown column 'tb_br.id' in 'on clause'")

2023-03-21 Thread Mike Bayer
GROUP BY, expression #1 of SELECT list contains > nonaggregated column 'tact_dev.tb_nv.id'; this is incompatible with > sql_mode=only_full_group_by") > > Do I need to aggregate? Or perhaps change sql_mode? > > Thanks! > > *From: *sqlalchemy@googlegroups.com on be

Re: [sqlalchemy] Working with an existing database, reflection and usage of ORM Declarative Mapping

2023-03-21 Thread Mike Bayer
his misconception is widespread, but maybe some tweaking of the > docs may have prevented this error. I'd be happy to contribute, but have > never pull requested to an open source repo. > > Anyway, thanks for the answer, wish you a pleasant day! > > Regards, > > Pierre &g

Re: [sqlalchemy] Working with an existing database, reflection and usage of ORM Declarative Mapping

2023-03-21 Thread Mike Bayer
hi - I think things would be easier if you defined your ORM mappings/ tables without relying upon reflection. There is no such requirement that reflection is used for an existing database, you just want to have ORM table metadata that matches the schema. the ORM/table metadata does not

Re: [sqlalchemy] Test query seems to spuriously give sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1054, "Unknown column 'tb_br.id' in 'on clause'")

2023-03-20 Thread Mike Bayer
glegroups.com on behalf > of Mike Bayer > *Date: *Monday, March 20, 2023 at 1:11 PM > *To: *noreply-spamdigest via sqlalchemy > *Subject: *Re: [sqlalchemy] Test query seems to spuriously give > sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1054, "Unknown > column

Re: [sqlalchemy] Test query seems to spuriously give sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1054, "Unknown column 'tb_br.id' in 'on clause'")

2023-03-20 Thread Mike Bayer
'tb_br.id' in 'on clause'") > > I’m guessing I’m missing something simple, but I have no idea what. > > Any (further) suggestions? > > > *From: *sqlalchemy@googlegroups.com on behalf > of Mike Bayer > *Date: *Saturday, March 18, 2023

Re: [sqlalchemy] Test query seems to spuriously give sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1054, "Unknown column 'tb_br.id' in 'on clause'")

2023-03-18 Thread Mike Bayer
the query emitted is: SELECT tb_nv.id, min(bs_3.build_id) AS min_1 FROM tb_nv, tb_brst AS bs_3, tb_brst AS bs INNER JOIN tb_vers AS v_2 ON bs.version_id = v_2.id INNER JOIN tb_brst AS bs_2 ON tb_br.id = bs_2.branch_id the error means that your ON clause refers to a table "tb_br" which is not

Re: [sqlalchemy] Using connection pools with individual PostgreSQL user logins for a backend REST API

2023-02-26 Thread Mike Bayer
I think you should use a single master login for create_engine() so that the pool deals with connections only at that top role. Then when you **use** connections, use PostgreSQL SET ROLE: https://www.postgresql.org/docs/current/sql-set-role.html to set the current role on the connection /

  1   2   3   4   5   6   7   8   9   10   >