Re: [sqlalchemy] sqlacodegen giving Unknown database on mysql+pymysql

2023-02-24 Thread Mike Bayer
Please refer to https://github.com/agronholm/sqlacodegen/discussions for sqlacodegen support. On Fri, Feb 24, 2023, at 8:12 AM, Andy Andurkar wrote: > I am getting the following error while using sqlcodegen with mysql > sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1049, >

Re: [sqlalchemy] sqlacodegen error : AttributeError: 'Table' object has no attribute 'bind'

2023-02-24 Thread Mike Bayer
Please refer to https://github.com/agronholm/sqlacodegen/discussions for sqlacodegen support. On Wed, Feb 22, 2023, at 11:25 AM, Yoav Kopfstein wrote: > I am using sqlacodegen for the first time to generate Python class models > from an existing PostgreSQL database. > > when running this : >

Re: [sqlalchemy] How to LOCK TABLE for PostgreSQL

2023-02-23 Thread Mike Bayer
On Thu, Feb 23, 2023, at 10:44 PM, jens.t...@gmail.com wrote: > Hello, > > In order to use the PostgreSQL LOCK > with SQLAlchemy, is there > a better way than > > *session.execute(sa.text(f"LOCK TABLE {Foo.__tablename__} IN SHARE MODE"))* I

Re: [sqlalchemy] Column vs InstrumentedAttribute

2023-02-23 Thread Mike Bayer
clear up... > >> On Feb 23, 2023, at 7:39 PM, Mike Bayer >> wrote: >> >> those are typing issues being reported by Pylance and do not affect the >> runtime behavior of the application. >> >> Pylance refers to typing stubs for SQLAlchemy 1.4 which don

Re: [sqlalchemy] some gotchas in SQLAlchemy 2.0 and how to fix

2023-02-23 Thread Mike Bayer
On Thu, Feb 23, 2023, at 9:53 AM, Victor Olex wrote: > Hi guys, > > I came across a bunch of issues in a relatively simple code I got when > upgraded to SQLA 2.0. Below I provided issues seen and solutions, but very > much welcome any corrections. I thought this might come in handy for some.

Re: [sqlalchemy] Column vs InstrumentedAttribute

2023-02-23 Thread Mike Bayer
those are typing issues being reported by Pylance and do not affect the runtime behavior of the application. Pylance refers to typing stubs for SQLAlchemy 1.4 which don't apply to SQLAlchemy 1.3. On Thu, Feb 23, 2023, at 7:36 PM, Val Huber wrote: > Hello, All > > In SQLAlchemy 1.4.29, the I

Re: [sqlalchemy] PG Array in declarative mapping

2023-02-21 Thread Mike Bayer
hey there - a list[str] can be lots of different kinds of datatype, like JSON, custom array types, and PG ARRAY, which is specific to PostgreSQL. so for non-obvious datatypes like this you indicate them explicitly: from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy import String

Re: [sqlalchemy] ext.hybrid.Comparator.property not implemented in SA2

2023-02-16 Thread Mike Bayer
On Thu, Feb 16, 2023, at 7:16 AM, Lele Gaifax wrote: > Hi all, > > while testing one of my tools[1] against SA2 I found that one test is > failing, and couldn't figure out a proper workaround. > > TL;DR > > Why is the sqlalchemy.ext.hybrid.Comparator.property explicitly > raising a

Re: [sqlalchemy] Seek for help - Python process stuck at _exec_once_mutex during first_connect in sqlalchemy/event/attr.py

2023-01-28 Thread Mike Bayer
that particular routine runs exactly once when the engine is used the very first time.I only see one traceback here that does not seem to indicate the lock is being called in a re-entrant fashion, so to look for deadlocks we would need to see tracebacks for all threads. if there is some

Re: [sqlalchemy] Re: Alembic and SA 2: upgrade ends with a rollback

2023-01-15 Thread Mike Bayer
, the two assertions succeed https://gist.githubusercontent.com/zzzeek/6ea76bb4c3bf50995bc7cc49b84ad88f/raw/9128670e40d4f5b2a3a77a66fb39d500d9a27012/gistfile1.txt On Sun, Jan 15, 2023, at 12:01 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > I'm able to add the as

Re: [sqlalchemy] Re: Alembic and SA 2: upgrade ends with a rollback

2023-01-15 Thread Mike Bayer
dev sqlite db or is this some production DB ? On Sun, Jan 15, 2023, at 11:09 AM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > can you add these assertions to env.py? > > > > with context.begin_transaction(): > > assert not context.get

Re: [sqlalchemy] Alembic and SA 2: upgrade ends with a rollback

2023-01-15 Thread Mike Bayer
4 with SQLALCHEMY_WARN_20=1 it *may* show some of these, if there were DDL or DML being emitted at least. But the debug lines for env.py I gave previously should also show if things are not lined up. On Sun, Jan 15, 2023, at 9:16 AM, Mike Bayer wrote: > can you add t

Re: [sqlalchemy] Alembic and SA 2: upgrade ends with a rollback

2023-01-15 Thread Mike Bayer
. On Sun, Jan 15, 2023, at 8:57 AM, Mike Bayer wrote: > It's not supposed to have this problem with a clean env.py.If you were > running commands on the connection() ahead of calling > context.begin_transaction(), that would explain things but I dont see that in > your example. >

Re: [sqlalchemy] Alembic with SQLite FOREIGN_KEYS pragma

2023-01-15 Thread Mike Bayer
On Sun, Jan 15, 2023, at 6:51 AM, Lele Gaifax wrote: > Hi all, > > this is loosely related to my other post: modern SA/Alembic transaction > handling changed (unsurprisingly! :-) somewhat, and old migration trick > does not work anymore. I found a way out, but maybe there is a better >

Re: [sqlalchemy] Alembic and SA 2: upgrade ends with a rollback

2023-01-15 Thread Mike Bayer
It's not supposed to have this problem with a clean env.py.If you were running commands on the connection() ahead of calling context.begin_transaction(), that would explain things but I dont see that in your example. short answer call connection.commit() at the end of the block , however

Re: [sqlalchemy] row.Row and dict behavior in 2.0

2023-01-12 Thread Mike Bayer
; Thanks and best regards, > > Matthew > > > On Monday, January 9, 2023 at 6:00:08 PM UTC-8 Mike Bayer wrote: >> >> >> On Mon, Jan 9, 2023, at 8:50 PM, mkmo...@gmail.com wrote: >>> Hello, >>> >>> It looks like in 2.0 we can no longer treat a ro

Re: [sqlalchemy] Adding OR () with do_orm_execute

2023-01-12 Thread Mike Bayer
if you have a select() construct, you can add new AND things just calling .where() again. e.g. existing_statement.where(or_(f1, f2)) . On Wed, Jan 11, 2023, at 11:26 PM, Val Huber wrote: > I am using this and it is working well to AND a series of filters to a > statement. > > But I do not

Re: [sqlalchemy] Determine transaction after_flush state

2023-01-12 Thread Mike Bayer
ing, in fact may have flushed any number of times”. > > Thanks for the again-quick response, if my presumption is correct, I am all > set. > > Regards, > Val > >> On Jan 11, 2023, at 6:22 PM, Mike Bayer >> wrote: >> >> >> a session can f

Re: [sqlalchemy] Determine transaction after_flush state

2023-01-11 Thread Mike Bayer
a session can flush any number of times, so what here determines "after" flush state as far as do_orm_execute()? do_orm_execute is not called within the flush itself (well, maybe it is...) If you see do_orm_executes inside of the flush, I guess you could look at session._flushing, is that

Re: [sqlalchemy] row.Row and dict behavior in 2.0

2023-01-09 Thread Mike Bayer
On Mon, Jan 9, 2023, at 8:50 PM, mkmo...@gmail.com wrote: > Hello, > > It looks like in 2.0 we can no longer treat a row.Row as a dict. I have a few > cases where I want to do this, such as when I need to get a list of columns, > or when I don't know the column name in advance. > > rows

Re: [sqlalchemy] Re: load_only when loading relatinoships from an instance

2023-01-05 Thread Mike Bayer
not as much set-ordering as gc, most likely. add populate_existing to the query, that also should force the lazy loader to take effect On Thu, Jan 5, 2023, at 9:00 AM, Mike Bayer wrote: > the "b" object in question is not really "lazy loaded" in the usual sense >

Re: [sqlalchemy] Re: load_only when loading relatinoships from an instance

2023-01-05 Thread Mike Bayer
the "b" object in question is not really "lazy loaded" in the usual sense here because it's already present in the session, that looks like an unexpire query. the delete() might be just changing something where the issue comes down to a set-ordering issue, perhaps. try adding

Re: [sqlalchemy] Re: this is a test message

2023-01-04 Thread Mike Bayer
continuing to test On Wed, Jan 4, 2023, at 7:32 PM, Michael Bayer wrote: > this is...another test! imagine that > > On Wednesday, January 4, 2023 at 7:27:10 PM UTC-5 Mike Bayer wrote: >> __ >> test > > > -- > SQLAlchemy - > The Python SQL Toolkit and

[sqlalchemy] this is a test message

2023-01-04 Thread Mike Bayer
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 message because

Re: [sqlalchemy] Speed performance

2022-12-07 Thread Mike Bayer
it's not clear what would cause the time delay, seems like a timeout after a deadlock of some kind. however first thing is that your async code is written incorrectly, as it is sharing the same AsyncSession among two concurrent async tasks, which will cause random errors at any number of

Re: [sqlalchemy] Re: Reflections on the SA 2.0 new PG Range

2022-12-04 Thread Mike Bayer
ax wrote: > Federico Caselli writes: > > > On Thursday, 1 December 2022 at 22:50:11 UTC+1 leleg...@gmail.com wrote: > > > >> "Mike Bayer" writes: > >> > > >> > well ".isempty" is not the kind of naming convention we like

Re: [sqlalchemy] Re: Reflections on the SA 2.0 new PG Range

2022-12-01 Thread Mike Bayer
On Thu, Dec 1, 2022, at 1:01 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > On Wed, Nov 30, 2022, at 2:31 PM, Lele Gaifax wrote: > >> "Mike Bayer" writes: > >> > >> > On Wed, Nov 30, 2022, at 10:30 AM, Lele Gaifax wrote: >

Re: [sqlalchemy] Re: Reflections on the SA 2.0 new PG Range

2022-11-30 Thread Mike Bayer
On Wed, Nov 30, 2022, at 2:31 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > On Wed, Nov 30, 2022, at 10:30 AM, Lele Gaifax wrote: > >> On the former one, it would be nice if we could reduce the "distance" > >> between th

Re: [sqlalchemy] Reflections on the SA 2.0 new PG Range

2022-11-30 Thread Mike Bayer
On Wed, Nov 30, 2022, at 10:30 AM, Lele Gaifax wrote: > Hi! > > I have finally completed the "port" of my application from SA 1.4 to SA > 2.0b. > > TL;DR I'm writing this report to ask an opinion about possible > "improvements" to the Range class. > > Given that the previous state was already

Re: [sqlalchemy] low-level commands in 2.0

2022-11-27 Thread Mike Bayer
vs > raising an Exception? one() has the Query semantics of raising errors if you dont get exactly one(), first() doesnt. in 2.0 style queries, first() does not automatically imply LIMIT on the query, that's one bigger difference. > > Zsolt > > > > > > > &

Re: [sqlalchemy] Learning to use new PG Ranges

2022-11-26 Thread Mike Bayer
well this fixes for now tusage = session.execute( select(func.sum(Usage.used_amount)) .where(Usage.date.op('<@')(cast(ccontract.validity, DATERANGE.scalar_one() otherwise what is happening is Usage.date.op(...)(Range(...)) doesn't have any way at the moment to know what

Re: [sqlalchemy] low-level commands in 2.0

2022-11-25 Thread Mike Bayer
On Thu, Nov 24, 2022, at 3:24 PM, zsol...@gmail.com wrote: > Hi, > > I'm trying to run low-level commands like DROP DATABASE / CREATE DATABASE, > with psycopg2. > > In 1.3 I used the following: > > with > pg_engine.connect().execution_options(isolation_level="AUTOCOMMIT",autocommit=True) >

Re: [sqlalchemy] "flatten" model columns in Row

2022-11-20 Thread Mike Bayer
the quickest way at the moment is to use select(X.__table__, y_col), or, if you use select(X), you can execute from session.connection().execute(). On Sat, Nov 19, 2022, at 5:31 PM, sector119 wrote: > Hello > > For example I have two models X and Y, I want to get all columns from X model >

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-11-12 Thread Mike Bayer
11, 2022, at 11:42 AM, Mike Bayer wrote: > We've identified a significant source of memory over-use in the 1.4 caching > system, on the particular environment where it was discovered, an extremely > long and complex query nonetheless created a cache key that used orders of > magnitude

Re: [sqlalchemy] How to Dispose of all Connections in a Pool in a Web Environment?

2022-11-11 Thread Mike Bayer
engine disposal is discussed in-depth at https://docs.sqlalchemy.org/en/14/core/connections.html#engine-disposal , so if that section is not clarifying then I'd want to know how it can be improved. your assertion would appear to be correct. On Fri, Nov 11, 2022, at 12:53 PM, mkmo...@gmail.com

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-11-11 Thread Mike Bayer
. On Thu, Nov 3, 2022, at 8:33 AM, Mike Bayer wrote: > > > On Thu, Nov 3, 2022, at 3:11 AM, 'Tony Cosentini' via sqlalchemy wrote: >> Hey, sorry for the crazy delay on this! >> >> We ended up turning off the cache in everything via query_cache_size and >> memory usag

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-11-03 Thread Mike Bayer
* It's a fairly sizable app (at least for the engines that have a lot of >> throughput) so we might be constantly adding keys to the cache and evicting >> stale ones (this one is more of a theory though). >> I'll report back if we see any changes. >> >> Thanks ag

Re: [sqlalchemy] Re: On new native PG Range in SA 2.0

2022-10-24 Thread Mike Bayer
On Mon, Oct 24, 2022, at 2:37 PM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > these look super great! > > Thanks! I will then open an issue and a related PR shortly. > > > We can make the text("") statements into something nicer in a se

Re: [sqlalchemy] Re: On new native PG Range in SA 2.0

2022-10-24 Thread Mike Bayer
these look super great! We can make the text("") statements into something nicer in a second pass, is that the part you didn't like ? On Mon, Oct 24, 2022, at 12:41 PM, Lele Gaifax wrote: > Hi, > > this is my first cut at the proposed methods: > > >

Re: [sqlalchemy] Override incorrectly defined classes

2022-10-24 Thread Mike Bayer
I dont think there's an obvious way to override declarative classes like that, but I also dont understand the problem such that something like that would be necessary (that is, I dont understand why you need "create tables on the fly", is this in a local testing database where you *do* create

Re: [sqlalchemy] Re: On new native PG Range in SA 2.0

2022-10-23 Thread Mike Bayer
On Sun, Oct 23, 2022, at 5:04 AM, Lele Gaifax wrote: > Lele Gaifax writes: > > > I will propose a PR soon. > > An ethical concern: given that the proposed methods are so simple, is it > legal/acceptable to verbatim copy them, and their tests, from the > psycopg (LGPL) and asyncpg (Apache

Re: [sqlalchemy] Re: On new native PG Range in SA 2.0

2022-10-23 Thread Mike Bayer
On Sun, Oct 23, 2022, at 4:13 AM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > Range is a really simple dataclass so adding a few simple value > > methods contains_value(), issubset(), issuperset() is a PR (with > > tests) away. there's no need t

Re: [sqlalchemy] On new native PG Range in SA 2.0

2022-10-22 Thread Mike Bayer
On Sat, Oct 22, 2022, at 6:57 AM, Lele Gaifax wrote: > Hi, > > as stated in > https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#range-and-multirange-types, > > in SA 2.0 the PG "range" (and "multirange") types are wrapped in a new > Range class, while the underlying driver-specific

Re: [sqlalchemy] Large increase in memory use when upgrading from 1.3 to 1.4

2022-10-20 Thread Mike Bayer
On Fri, Oct 21, 2022, at 12:00 AM, 'Tony Cosentini' via sqlalchemy wrote: > Hi, > > We recently upgraded our application (a Flask web app) from SQLAlchemy 1.3.19 > to 1.4.41. > > Overall things are stable, but we have noticed a very large increase in > memory use: > Screen Shot 2022-10-21 at

Re: [sqlalchemy] SELECT .. BULK COLLECT INTO ...

2022-10-05 Thread Mike Bayer
Select does not have a hook for that particular spot in the SQL compilation, so unless you rewrote all of visit_select, your best bet is to stick with simple string replacement. this does not in any way preclude you from using the compiler extension, get the text from the compiler then do

Re: [sqlalchemy] Possible to pass array of (table, conditions) to join() like where()/select() ?

2022-09-16 Thread Mike Bayer
On Fri, Sep 16, 2022, at 12:10 PM, mkmo...@gmail.com wrote: > I use the following pattern in my REST APIs, building up the select, joins, > where conditions, group bys, order bys, depending on the query parameters > passed in by the user: > > selects = [Foo] > joins = [(Bar, Foo.c.id

Re: [sqlalchemy] SQLAlchemy 2. psycopg3 type adapt

2022-09-11 Thread Mike Bayer
value that would be it On Sun, Sep 11, 2022, at 8:09 AM, sector119 wrote: > Thank You, Mike, I thought that I can adapt types with sqlalchemy, not with > db adapter like psycopg, to make it not db adapter dependent solution. > > воскресенье, 11 сентября 2022 г. в 04:14:02 UTC+3

Re: [sqlalchemy] SQLAlchemy 2. psycopg3 type adapt

2022-09-10 Thread Mike Bayer
maybe email on the psycopg2 list / github tracker On Sat, Sep 10, 2022, at 4:15 PM, sector119 wrote: > Hello, > > I got exception when I try to insert numpy.int8 type data. > sqlalchemy.exc.ProgrammingError: (psycopg.ProgrammingError) cannot adapt type > 'int8' using placeholder '%s' (format:

Re: [sqlalchemy] Using Mapped[str | None]

2022-08-31 Thread Mike Bayer
str | None" union type, but I'll stick more > detail in the issue. > > Not having to import Optional or Union everywhere is one of the nice > ergonomic improvements to typing of late. > > Cheers:) > > On Wednesday, 31 August 2022 at 23:32:37 UTC+10 Mike Bayer wrot

Re: [sqlalchemy] Using Mapped[str | None]

2022-08-31 Thread Mike Bayer
On Wed, Aug 31, 2022, at 5:00 AM, Peter Schutt wrote: > Hi, > > I've been using 2.0 from main and notice that annotating an attribute with > `mapped[str | None]` raises with: > > sqlalchemy.exc.ArgumentError: Could not locate SQLAlchemy Core type for > Python type: str | None > > > I've

Re: [sqlalchemy] Non-repeatable reads, vectorized refresh

2022-08-24 Thread Mike Bayer
; > вторник, 23 августа 2022 г. в 22:34:23 UTC+3, Mike Bayer: >> >> >> On Tue, Aug 23, 2022, at 3:00 PM, Evgenii wrote: >>> >>> >>> Thanks a lot! >>> I used “vectorized” for sqlalchemy.orm.Session.refresh method and mean that >&g

Re: [sqlalchemy] Non-repeatable reads, vectorized refresh

2022-08-23 Thread Mike Bayer
on.query(InstrumentTable).filter(InstrumentTable.id.in_([id1, > id2, ..., idn])).all() > *# and sort res with given ids order* ` > is much faster than (especially in low network connections): > > `instuments = [session.query(InstrumentTable).get(id_) *for* id_ *in* [id1, > id2, .

Re: [sqlalchemy] Non-repeatable reads, vectorized refresh

2022-08-23 Thread Mike Bayer
On Tue, Aug 23, 2022, at 1:50 PM, Evgenii wrote: > Hi there! > > > > Please help me to understand: > I want to make two equal queries, that sends real queries to database each > time: > > > `session.query(InstrumentTable).get(instr_id) > > session.query(InstrumentTable).get(instr_id) ` >

Re: [sqlalchemy] How to Warm Up Connection Pool ?

2022-08-23 Thread Mike Bayer
On Tue, Aug 23, 2022, at 1:54 PM, mkmo...@gmail.com wrote: > As stated in the docs: > > > All SQLAlchemy pool implementations have in common that none of them “pre > > create” connections - all implementations wait until first use before > > creating a connection > > Is it possible to warm

Re: [sqlalchemy] database operation fails after succsefull multi-processing.

2022-08-23 Thread Mike Bayer
happen on every run. I'm not entirely sure how to run it on a > different server, I'm fairly new to databases. I'm running "mysql Ver 8.0.30 > for Linux on x86_64 (MySQL Community Server - GPL)". > The issue does not occur when using pymysql. > On Tuesday, 23 August 202

Re: [sqlalchemy] database operation fails after succsefull multi-processing.

2022-08-23 Thread Mike Bayer
also try the pymysql DBAPI if that changes things, if this is mariadb try mariadb-connector also. On Tue, Aug 23, 2022, at 12:04 PM, Mike Bayer wrote: > it happens every time the program is run? there's nothing really going on > in the program here, if I take out the initi

Re: [sqlalchemy] database operation fails after succsefull multi-processing.

2022-08-23 Thread Mike Bayer
uery(query) > File > "/home/talens/anaconda3/envs/hatpi/lib/python3.9/site-packages/MySQLdb/cursors.py", > line 319, in _query > db.query(q) > File > "/home/talens/anaconda3/envs/hatpi/lib/python3.9/site-packages/MySQLdb/connections.py", > line 259

Re: [sqlalchemy] database operation fails after succsefull multi-processing.

2022-08-22 Thread Mike Bayer
your program runs completely (thanks), and I can't reproduce any problem. changed line 1 as written to: # Line 1. # If nothing happens on line 1, line 3 fails. insert_integer(0) # If I do this (insert-only) line 3 fails. #database_action(0) # If I do this (query, insert) line

Re: [sqlalchemy] Relationships between different databases?

2022-08-17 Thread Mike Bayer
you can query the three databases with one session, docs on that are at https://docs.sqlalchemy.org/en/14/orm/persistence_techniques.html#simple-vertical-partitioning from there, you can make *really basic* relationships between classes that are in two databases. as far as how they load, it

Re: [sqlalchemy] Many-to-Many association table with 3 foreign-key columns

2022-08-16 Thread Mike Bayer
There is no automatic or implied coordination against the survey_answer table as indicated in the "secondary" field. You need to not add entries to Survey.answers, Survey.questions as is, those would be viewonly=True as long as they refer to survey_answer as "secondary".Instead, create

Re: [sqlalchemy] Reflecting a postgreSQL database with extensions?

2022-08-16 Thread Mike Bayer
they are safe to ignore. they might work if you install https://geoalchemy-2.readthedocs.io/en/latest/ if they include reflection support. you can also implement an event hook where you can provide for your own logic to supply a type object (but you'd need to have stub classes for those

Re: [sqlalchemy] SQLAlchemy 2 and Dialect’s has_schema()

2022-08-01 Thread Mike Bayer
On Sun, Jul 31, 2022, at 10:15 PM, jens.t...@gmail.com wrote: > Hello, > > I’m curious to get recommendations about the following use-case (based on > this SO Answer > ): > > *>>> import sqlalchemy*

Re: [sqlalchemy] Re: With declarative_base() can I assign different mappings to different engines?

2022-07-29 Thread Mike Bayer
Base(metaclass=CommonMeta): pass class Base(CommonBase): pass > > Jens > > > On Saturday, July 30, 2022 at 6:47:24 AM UTC+10 Mike Bayer wrote: >> >> yes use the recipe given at >> https://docs.sqlalchemy.org/en/14/orm/declarative_styles.html#creating-an-explic

Re: [sqlalchemy] Re: With declarative_base() can I assign different mappings to different engines?

2022-07-29 Thread Mike Bayer
On Fri, Jul 29, 2022, at 12:16 AM, jens.t...@gmail.com wrote: > After digging through docs and some more code, here’s what seems to work. > > The single, shared package should not generate that *Base* class which is > then used by other packages. Instead, it now provides a function that >

Re: [sqlalchemy] ".contains" query with VARBINARY Column

2022-07-13 Thread Mike Bayer
element.html > > Specifically: > 1. ColumnOperators.endswith() > 2. ColumnOperators.contains() > 3. ColumnOperators.like() > 4. ColumnOperators.startswith() > I created this issue with suggested text > https://github.com/sqlalchemy/sqlalchemy/issues/8253 > > Peter &g

Re: [sqlalchemy] ".contains" query with VARBINARY Column

2022-07-13 Thread Mike Bayer
you're sending a Python bytestring as the expression for which there's no explicit support for operators like concat, contains, etc. the solution is to build the SQL composition directly using func.concat , or just building up the LIKE expression in Python, so that there's no ambiguity

Re: [sqlalchemy] Making a unique key from two non-unique fields with reflected database?

2022-07-11 Thread Mike Bayer
On Sun, Jul 10, 2022, at 11:36 PM, Carl Brewer wrote: > On 11/07/2022 1:19 am, Mike Bayer wrote: > > background on mapping ORM classes to reflected tables is at > > https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#mapping-declaratively-with-reflected-tables &

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
22, at 1:30 PM, Montana Burr wrote: > > I see, thank you for the assistance. > > Doing stuff like this would be a LOT easier if there was an equivalent to > "SELECT *" > On Sunday, July 10, 2022 at 10:54:19 AM UTC-6 Mike Bayer wrote: >> __ >>

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
m trying to do - access an apparently > nonexistent column (apologies if I didn't make that clear earlier). > > I just ran your program with that change and was able to reproduce the > original error, so I'm assuming that either both of our queries are wrong, or > the code in the &qu

Re: [sqlalchemy] How do I access a column that is the result of an outerjoined subquery?

2022-07-10 Thread Mike Bayer
I've converted your fragments into a full MCVE and it runs fine, no error is generated. would need to see a stack trace. Try out the program below also. import datetime from sqlalchemy import Column from sqlalchemy import create_engine from sqlalchemy import Date from sqlalchemy import

Re: [sqlalchemy] Making a unique key from two non-unique fields with reflected database?

2022-07-10 Thread Mike Bayer
background on mapping ORM classes to reflected tables is at https://docs.sqlalchemy.org/en/14/orm/declarative_tables.html#mapping-declaratively-with-reflected-tables and there are three general methods depending on your needs. DeferredReflection is oriented towards explicit class setup, and

Re: [sqlalchemy] Difference between SQLAlchemy Select and Query API

2022-07-03 Thread Mike Bayer
On Sun, Jul 3, 2022, at 10:41 AM, Yaakov Bressler wrote: > *I saw the following Q posted on SO:* > > Difference between SQLAlchemy Select and Query API > > Not sure if this has been asked before,

Re: [sqlalchemy] sqlalchemy serialization bug (TypeError: list indices must be integers or slices, not str)

2022-06-24 Thread Mike Bayer
1.4.39 is released On Fri, Jun 24, 2022, at 12:12 PM, Evgenii wrote: > Yes, it works > > пятница, 24 июня 2022 г. в 17:58:46 UTC+3, Evgenii: >> Sure, I can >> >> пятница, 24 июня 2022 г. в 17:06:39 UTC+3, Mike Bayer: >>> __ >>> if you can test th

Re: [sqlalchemy] sqlalchemy serialization bug (TypeError: list indices must be integers or slices, not str)

2022-06-24 Thread Mike Bayer
dict["ext.mutable.values"][key]: +val._parents[state] = key event.listen(parent_cls, "load", load, raw=True, propagate=True) event.listen( On Fri, Jun 24, 2022, at 10:01 AM, Mike Bayer wrote: > hey there - > > yes this is u

Re: [sqlalchemy] sqlalchemy serialization bug (TypeError: list indices must be integers or slices, not str)

2022-06-24 Thread Mike Bayer
hey there - yes this is unfortunately the case as we had to fix a bug in the mutable extension, issue 8133 doc'ed at https://docs.sqlalchemy.org/en/14/changelog/changelog_14.html#change-f8b03063d70397a8f275287ed2c8f2e6 . this seemed to be enough of an edge case that I didn't attempt to

Re: [sqlalchemy] Inheritance Hierarchies: Loading a model created with parent class in same session

2022-06-20 Thread Mike Bayer
On Sun, Jun 19, 2022, at 3:52 PM, David Bücher wrote: > To avoid writing a function selecting the correct class for a 'type' value, I > would like to create models using the parent class ('Employee') and 'type' > instead of using the child class ('Manager', 'Engineer') in the first place.

Re: [sqlalchemy] Standard M:N secondary association table relationship pattern warnings

2022-06-05 Thread Mike Bayer
apply viewonly=True to those relationships that you aren't going to be append()'ing towards. the warnings are trying to indicate that if you have a certain Xs, and you append a certain Ys to it, but at the same time, you also create an XY_assoc object with those same Xs/Ys and also append that

Re: [sqlalchemy] Getting Nonetype instead of None on query

2022-06-01 Thread Mike Bayer
On Wed, Jun 1, 2022, at 4:27 PM, Alexei Kositsin wrote: > From alchemy docs I should get None if search is empty, > https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.query.Query.one_or_none > > But getting Nonetype instead (a class), why so? no known reason for such a thing to

Re: [sqlalchemy] Upgrading from 1.3.23 to 1.4.x subquery seems stricter

2022-05-29 Thread Mike Bayer
On Sun, May 29, 2022, at 12:32 AM, gbr wrote: > In SQLA 1.3.x, I used to follow this pattern to construct a query: > > ``` > def load_something(... sort=False): >qry = select(columns=..., from_obj=...) >if sort: > qry = qry.order_by(desc(qry.c.created_on)) >if ... > qry =

Re: [sqlalchemy] add/update causing InvalidRequest for object with association_proxy lookup

2022-05-16 Thread Mike Bayer
_on_commit to False.See the docs recently clarified at https://docs.sqlalchemy.org/en/14/orm/session_basics.html#session-committing . On Mon, May 16, 2022, at 2:14 PM, Mike Bayer wrote: > that error message still describes an object that isn't associated with a > Session. If y

Re: [sqlalchemy] add/update causing InvalidRequest for object with association_proxy lookup

2022-05-16 Thread Mike Bayer
' cannot proceed (Background on this error at: > http://sqlalche.me/e/14/bhk3) > ``` > > Thanks > > Nathan > On Wednesday, 11 May 2022 at 15:25:11 UTC+1 Mike Bayer wrote: >> __ >> the pattern you are using with expunge() is likely creating confusion as to >>

Re: [sqlalchemy] add/update causing InvalidRequest for object with association_proxy lookup

2022-05-11 Thread Mike Bayer
the pattern you are using with expunge() is likely creating confusion as to what objects are still in the Session and which ones aren't. I would seek to organize your application such that the entire sequence of load/manipulation operations with a set of objects proceeds under a single

Re: Import data to alembic migrations

2022-05-10 Thread Mike Bayer
yes, one particular approach to this issue is discussed here: https://alembic.sqlalchemy.org/en/latest/front.html#installation start with that if nothing else is working (There are many ways to do this). On Tue, May 10, 2022, at 5:34 AM, Ilya Demidov wrote: > Hi! > > I have some problem. I

Re: [sqlalchemy] Re: Problem with PG ARRAY's ANY() and SA 1.4.36 (maybe related resolution of #6515 ?)

2022-05-03 Thread Mike Bayer
the fix has merged so if you want to test the rel_1_4 branch that will confirm you have what you need. On Tue, May 3, 2022, at 3:35 AM, Lele Gaifax wrote: > "Mike Bayer" writes: > > > a fix for that is coming through at > > https://github.com/sqlalchemy/sqlalchemy

Re: [sqlalchemy] Problem with PG ARRAY's ANY() and SA 1.4.36 (maybe related resolution of #6515 ?)

2022-05-01 Thread Mike Bayer
a fix for that is coming through at https://github.com/sqlalchemy/sqlalchemy/issues/7979 though it's best to give types to bindparam() objects if they don't have a value On Sun, May 1, 2022, at 11:53 AM, Mike Bayer wrote: > it looks like the bindparam() when not given a type is being coer

Re: [sqlalchemy] Problem with PG ARRAY's ANY() and SA 1.4.36 (maybe related resolution of #6515 ?)

2022-05-01 Thread Mike Bayer
it looks like the bindparam() when not given a type is being coerced to thinking it's an ARRAY, which might be a separate issue, but in any case, give it a type so that there is no ambiguity (do you really need to use bindparam() directly?) conn.execute( table.select().where(

Re: [sqlalchemy] Problem with PG ARRAY's ANY() and SA 1.4.36 (maybe related resolution of #6515 ?)

2022-05-01 Thread Mike Bayer
If you could post some code examples on a github discussion that I can run, that would be helpful. the change basically fixed the any/all operations to correctly interpret incoming arguments so that proper casts could be provided. I dont use these operators myself so it could be that

Re: [sqlalchemy] Session within a session

2022-04-20 Thread Mike Bayer
you can work with multiple sessions and their objects simultaneously, with the provision that you don't add() an object from one session directly into the other one, without detaching it from the original session first. to transfer the state of an object from one session to another without

Re: [Renaming Alembic Table]

2022-04-11 Thread Mike Bayer
On Mon, Apr 11, 2022, at 12:47 AM, arvind aithal wrote: > Is it possible to rename the alembic table name to customised one? > > Once we run the migrations it creates *alembic_version table* which stores > the version. > > After init, when we run command migrate, by default it generates >

Re: [sqlalchemy] AttributeError("module 'sqlalchemy' has no attribute 'dialects'"

2022-04-07 Thread Mike Bayer
i dont know i would need to see the calling code On Thu, Apr 7, 2022, at 6:17 AM, Evgenii wrote: > > Hello! > Thank you for the previous answer. > > > I use prefect and dask to execute workflows, that use SA inside and I get > very strange errors periodically: > > `Task 'HE Quotes[5]':

Re: [sqlalchemy] Cascade_backrefs Behavior Deprecated For Removal In 2.0

2022-04-05 Thread Mike Bayer
d as global registries tend to be forgotten and contribute to the "implicitness" of a program. > > On Tuesday, April 5, 2022 at 11:58:33 AM UTC-7 Mike Bayer wrote: >> >> >> On Tue, Apr 5, 2022, at 1:02 PM, Thorsten von Stein wrote: >>> I'm currently tryi

Re: [sqlalchemy] Cascade_backrefs Behavior Deprecated For Removal In 2.0

2022-04-05 Thread Mike Bayer
On Tue, Apr 5, 2022, at 1:02 PM, Thorsten von Stein wrote: > I'm currently trying to get my applications ready for SQLAlchemy 2.0. A > change that has forces code changes in numerous places is the removal of the > automatic addition of new instances to the session upon establishing a >

Re: [sqlalchemy] Type hints for result objects from orm select

2022-04-04 Thread Mike Bayer
We dont have a system for per-column type hinting right now.pep-484 and related peps unfortunately do not support effective means of representing custom tuple-like structures. The closest they have is pep-646, but unfortunately this pep does not provide enough functionality for database

Re: [sqlalchemy] SQLAlchemy + multiprocessing problems

2022-03-31 Thread Mike Bayer
when using multiprocessing, the connection pool in the new process must be replaced with a new one. This is usually accomplished by calling engine.dispose(). However, to maintain the pool in the parent process as well, replace the connection pool alone without disposing the old one:

Re: [sqlalchemy] Integrating graphene-sqlalchemy-filter into graphene-sqlalchemy

2022-03-30 Thread Mike Bayer
we dont maintain graphene-sqlalchemy-filter on this list, you would need to reach out to the developers of that library. On Wed, Mar 30, 2022, at 2:30 PM, Peter Harrison wrote: > Hello everyone, > > My organization uses both graphene-sqlalchemy and graphene-sqlalchemy-filter > for some

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread Mike Bayer
an instance but there's a lot of cases to be worked out. On Mon, Mar 28, 2022, at 2:05 PM, Mike Bayer wrote: > > > On Mon, Mar 28, 2022, at 1:31 PM, mkmo...@gmail.com wrote: >> Hi Mike, >> >> When using `column_property`, this >> `select(User).from_stateme

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-28 Thread Mike Bayer
o2').where(User.id > == user.id).returning(*select(User).selected_columns))) > user = res.scalars().one() > # no extra query > print(user.full_name) > > Thanks and best regards, > > Matthew > > > On Sunday, March 27, 2022 at 7:28:55 PM UTC-7 Mike Bayer wro

Re: [sqlalchemy] Looking for help with interpreting an error/debugging

2022-03-28 Thread Mike Bayer
aDB claims to be compatible… I’ll try that! > > Jens > > > On Monday, March 28, 2022 at 10:35:56 PM UTC+10 Mike Bayer wrote: >> __ >> hey there - >> >> never seen that before so it is very likely to be an issue specific to >> mariadbconnector, wh

Re: [sqlalchemy] Looking for help with interpreting an error/debugging

2022-03-28 Thread Mike Bayer
hey there - never seen that before so it is very likely to be an issue specific to mariadbconnector, which is a much lesser-used driver. suggestions are to seek help from mariadb connector devs directly, in the interim try mysqlclient or pymysql to see if the issue resolves, or shows a better

Re: [sqlalchemy] How to infer the ORM model class from an update()/insert() object?

2022-03-27 Thread Mike Bayer
odel).selected_columns) # this will apply > the column_property to the RETURNING > row = session.execute(upd).one() > > Now I just need to take this row and convert it to an ORM object. > > Is there a public API I can use to take a Core `row` and convert it to an ORM

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