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

2022-11-30 Thread Lele Gaifax
"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 the new Range class and what popular drivers provide: >> >> - "empty" vs "isempty": both asyncpg and psycopg have a "isempty" >>

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

[sqlalchemy] Reflections on the SA 2.0 new PG Range

2022-11-30 Thread Lele Gaifax
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 "clean" (that is, executing the test suite with SQLALCHEMY_WARN_20=1 did

Re: [sqlalchemy] low-level commands in 2.0

2022-11-27 Thread Mike Bayer
On Sat, Nov 26, 2022, at 5:28 PM, Zsolt Ero wrote: > Thanks, so far my new project works well in 2.0. My question is that I'm > trying to migrate to the 2.0 style form using this cheetsheet: > > https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-orm-usage > > So far I

Re: [sqlalchemy] low-level commands in 2.0

2022-11-26 Thread Zsolt Ero
Thanks, so far my new project works well in 2.0. My question is that I'm trying to migrate to the 2.0 style form using this cheetsheet: https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#migration-orm-usage So far I couldn't figure out how to turn this query in to 2.0 style.

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

[sqlalchemy] Learning to use new PG Ranges

2022-11-26 Thread Lele Gaifax
Hi, now and then I'm spending some time migrating one app from SA v1.4 to v2: most of the porting problems stem from the new PG Range class, and today I hit the following, that I'm not sure how I should fix. This script is a contrived example, reducing the real code down to the essential:

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

[sqlalchemy] raw sql mapping to class

2022-11-25 Thread Flavio Silva
Hello ! I'm developing a new process of extracting data from one database and writing to another, and believed that sqlalchemy has many features that can help me in the that. Looking in the documentation, especifically, in the case of "Getting ORM results from Textual and Core Statements

[sqlalchemy] Re: low-level commands in 2.0

2022-11-24 Thread zsol...@gmail.com
This is what I see with echo=True using the following block: select pg_catalog.version() [raw sql] {} select current_schema() [raw sql] {} show standard_conforming_strings [raw sql] {} BEGIN (implicit; DBAPI should not BEGIN due to autocommit mode) DROP DATABASE IF EXISTS md_server [raw sql]

[sqlalchemy] low-level commands in 2.0

2022-11-24 Thread zsol...@gmail.com
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) as conn: conn.execute(command) Now in 2.0 I run into many errors. I've

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

2022-11-20 Thread sector119
Thank you, Mike! воскресенье, 20 ноября 2022 г. в 16:31:09 UTC+2, 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: >

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 >

[sqlalchemy] "flatten" model columns in Row

2022-11-19 Thread sector119
Hello For example I have two models X and Y, I want to get all columns from X model and only one or two cols from Y model in the same Row as [(x_col1, x_col2, x_col3, y_col1), ...] but not [(X, y_col1)] as I get when I perform select(X, Y.col1).join(X.y) I just don't want to write all X model

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

2022-11-13 Thread 'Tony Cosentini' via sqlalchemy
Oh wow, this sounds like it would definitely impact us. I'm out this week travelling, but I will definitely upgrade + re-enable the cache and report back. Thanks! On Sat, Nov 12, 2022 at 3:17 PM Mike Bayer wrote: > 1.4.44 is released with this change. if you can try it out with your >

[sqlalchemy] Re: sqlacodegen getting error

2022-11-13 Thread Lele Gaifax
Ajay Raikar writes: > can you suggest any other good ORM that can auto-generate DB > classes...? I cannot really say anything on the "goodness" of other ORMs, but I guess that is a "frequently asked facility". A quick search reveals for example

[sqlalchemy] Re: sqlacodegen getting error

2022-11-13 Thread Ajay Raikar
Hey Ciao lele, Thanks for your reply. I will report this to sqlacodegen team. Also, can you suggest any other good ORM that can auto-generate DB classes...? Thanks & Regards, Ajay Raikar On Sunday, 13 November 2022 at 18:09:26 UTC+5:30 leleg...@gmail.com wrote: > Ajay Raikar writes: > > >>

[sqlalchemy] Re: sqlacodegen getting error

2022-11-13 Thread Lele Gaifax
Ajay Raikar writes: >> n\codegen.py", line 9, in >> from inspect import ArgSpec >> ImportError: cannot import name 'ArgSpec' from 'inspect' (C:\Program >> Files\Pythoon311\Lib\inspect.py) >> Apparently the ArgSpec has been removed after a long deprecation period in

[sqlalchemy] sqlacodegen getting error

2022-11-13 Thread Ajay Raikar
Hi Team, I have installed a fresh project in which i wanted to generate ms-sql db class models with help of sqlacodegen I was not able to do that getting this error as attached in screenshot. Also I did the pip check it says no broken requirement. Even I tried down grading SQLAlchemy to

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

2022-11-12 Thread Mike Bayer
1.4.44 is released with this change. if you can try it out with your application and let me know if you see improvements in memory use for your memory-intensive case, that would be much appreciated! thanks https://www.sqlalchemy.org/blog/2022/11/12/sqlalchemy-1.4.44-released/ On Fri, Nov

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

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

2022-11-11 Thread mkmo...@gmail.com
I'm using the standard connection pool via engine: engine = sqlalchemy.create_engine('oracle://scott:tiger@foo', ...) conn1 = engine.connect() conn2 = engine.connect() I want to dispose and recreate the pool in a web environment. All new threads that connect should get a new

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

2022-11-11 Thread Mike Bayer
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 more memory than the statement itself. A fix for this

Re: [sqlalchemy] Breaking Integration with Locust Tests? Having a hard time debugging

2022-11-07 Thread Simon King
The stack trace shows that the exception is being raised in sqlalchemy_utils/types/uuid.py. Looking at sqlalchemy_utils on Github, this is a bug that has been reported and fixed, but the fix hasn't been released yet: https://github.com/kvesteri/sqlalchemy-utils/pull/643 You could either install

Re: [sqlalchemy] Breaking Integration with Locust Tests? Having a hard time debugging

2022-11-04 Thread Nishant Varma
It seems to have something to do with a non-numeric version. What is the SQLAlchemy verson? Check this issue https://github.com/oracle/python-cx_Oracle/issues/27 to see if it connected. On Sat, Nov 5, 2022, 4:52 AM 'Theo Chitayat' via sqlalchemy < sqlalchemy@googlegroups.com> wrote: > I have a

[sqlalchemy] Breaking Integration with Locust Tests? Having a hard time debugging

2022-11-04 Thread 'Theo Chitayat' via sqlalchemy
I have a model that uses ChoiceType like an enum for my FastAPI app. As soon as I install *locust* from pip, i get errors like this: *from sqlalchemy_utils import ChoiceType File

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

2022-11-03 Thread Mike Bayer
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 usage returned to previous levels. We also didn't see any noticeable > change in CPU usage in

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

2022-11-03 Thread 'Tony Cosentini' via sqlalchemy
Hey, sorry for the crazy delay on this! We ended up turning off the cache in everything via query_cache_size and memory usage returned to previous levels. We also didn't see any noticeable change in CPU usage in our web servers. We did see a pretty noticable perf regression in a worker job

[sqlalchemy] Re: Missing PoolListener in 1.4 and sql_mode

2022-10-29 Thread ••
Sorry this seems to work! *def create_engine(database_url, **kwargs):if kwargs:engine = _create_engine(database_url, **kwargs)else:engine = _create_engine(database_url, pool_pre_ping=True, pool_recycle=3600)* *@event.listens_for(**engine**, 'connect',

[sqlalchemy] Missing PoolListener in 1.4 and sql_mode

2022-10-28 Thread ••
Hi, I'm trying to move from 1.3 to 1.4 and immediately hit the issue with sqlalchemy.interfaces being removed. Basically, we have a wrapper around create_engine() that looks something like this: *from sqlalchemy.engine import create_engine as _create_enginefrom

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-27 Thread Simon King
I can't see anything obviously wrong with your code. If you turn on debug logs, you'll be able to see the SQL that is being executed, and the rows that are coming back. Paste those logs here and maybe we'll be able to help more. Simon On Tue, Oct 25, 2022 at 2:38 PM Abdellah ALAOUI ISMAILI <

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-25 Thread Abdellah ALAOUI ISMAILI
yes, all tags have a color... Can you suggest me another way to do this, please? thank you . Le mardi 25 octobre 2022 à 10:52:17 UTC+1, Simon King a écrit : > Turn on debug logs (add echo="debug" to your db connection string) to see > the SQL you are executing and the results you are getting

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-25 Thread Simon King
Turn on debug logs (add echo="debug" to your db connection string) to see the SQL you are executing and the results you are getting back: https://docs.sqlalchemy.org/en/14/core/engines.html#sqlalchemy.create_engine.params.echo Are you sure that the database actually contains colours for those

Re: [sqlalchemy] Override incorrectly defined classes

2022-10-24 Thread Nishant Varma
Thanks for the reply, Mike. In that case, I'll just keep a copy of our definitions in the test case folder and correct them whenever required. Hopefully, these will get merged to the real code sooner or later (which is why I wanted to name it backlogs). The goal is to stage tables(which are

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 second > > pass, is that the part you didn't like ? >

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

2022-10-24 Thread Lele Gaifax
"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 second > pass, is that the part you didn't like ? Not exactly: I spent some time trying to avoid the "redundancy" in the

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

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

2022-10-24 Thread Lele Gaifax
Hi, this is my first cut at the proposed methods: https://github.com/lelit/sqlalchemy/commit/b9a2a7761ec292536a7be37703d20800edfab3f0 I'm not quite happy with how I wrote the tests, because I didn't find a reasonable way to get the PG representation of a given Range instance, and thus I

[sqlalchemy] Override incorrectly defined classes

2022-10-24 Thread Nishant Varma
We use SQLAlchemy to read/write data, but not create tables (as it done by DBAs). Due to this, some of the definitions which are incorrect, have not yet been caught (though it works for reads/writes etc.). Is there a DRY way to to override them for testing purposes (create tables on the fly

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 to "proxy" things, these are pretty > >

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

2022-10-23 Thread Lele Gaifax
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 license)? ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello

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

2022-10-23 Thread Lele Gaifax
"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 to "proxy" things, these are pretty > obvious methods to just implement directly. I would just disagree with >

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] iterate sqlalchemy query over for loop in my template python-flask

2022-10-22 Thread Abdellah ALAOUI ISMAILI
wheel ... in my template, I get just the first tag color, returned from the function. this is the result of my HTML file source code : LOG EXADATA DMZ_PRIVE I hope it's clear, thank you . Le vendredi 21 octobre 2022 à 09:23:48 UTC+1, Simon King a écrit : > I don't

[sqlalchemy] On new native PG Range in SA 2.0

2022-10-22 Thread Lele Gaifax
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 class is "hidden" within the dialect implementation. This means that

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

2022-10-21 Thread 'Tony Cosentini' via sqlalchemy
Hi Mike, Thanks for such a fast reply! We tried setting query_cache_size on a canary environment today, will be rolling it out widely on servers on Monday and can report back on if it has a noticeable impact. After thinking about this more, I think our situation might exacerbate things a bit,

Re: [sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-21 Thread Simon King
I don't understand the question. Are you saying that only one tag is displayed? If so, that's not a problem with SQLAlchemy, it's a problem with your template logic. If that's not what you mean, you need to give us more information. What is the value of "server.tags", and what is the output from

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

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

2022-10-20 Thread 'Tony Cosentini' via sqlalchemy
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: [image: Screen Shot 2022-10-21 at 11.26.18 AM.png] Is this from the new query caching feature? I'm planning on

[sqlalchemy] iterate sqlalchemy query over for loop in my template python-flask

2022-10-20 Thread Abdellah ALAOUI ISMAILI
Hello, I call a function in my template that returns sqlalchemy query result, (color value from the name of the tag). this is the query function : *def get_tag_color(name): * *return db.session.query(Tag.tag_color).filter(Tag.tag_name == name).scalar() * and I call it in my template file: * {%

[sqlalchemy] how can I select schema while using sqlacodegen crawling postgresql db models

2022-10-11 Thread Ryan Lee
when I prepare crawling db dto from postgresql( AWS RDS) for my flask application, I set SQLAlchemy URI like follow f'{RDS_PROTOCOL}://{RDS_USERNAME}:{RDS_PASSWORD}@{RDS_HOSTNAME}:{RDS_PORT}/{RDS_DB_NAME}' but I don't know how to define one specific schema pls let me knowTT -- SQLAlchemy

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

2022-10-05 Thread mkmo...@gmail.com
Perfect, thank you Mike. Best regards, Matthew On Wednesday, October 5, 2022 at 11:51:39 AM UTC-7 Mike Bayer wrote: > 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

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

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

2022-10-05 Thread mkmo...@gmail.com
Hello, I am generating Oracle PLSQL using sqlalchemy core. I would like to generate the following output: SELECT foo, bar BULK COLLECT INTO l_foos FROM baz; Is there a mechanism to insert a string after the select column list and before the FROM? In sql/compiler.py:visit_select

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

2022-09-17 Thread mkmo...@gmail.com
Thanks! On Friday, September 16, 2022 at 10:53:59 AM UTC-7 Mike Bayer wrote: > > > 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 >

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

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

2022-09-16 Thread mkmo...@gmail.com
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 == Bar.c.foo_id)] where_conditions = [Foo.c.id == request.args['pk']]

Re: [sqlalchemy] Can’t make the Composite Comparator work…

2022-09-16 Thread jens.t...@gmail.com
Thank you Simon! That worked indeed and makes a lot of sense. I think I misinterpreted the documentation a bit in that sense; it did puzzle that SQLA would patch all these mapped objects… Based on your example: *>>> dbsession.query(Vertex).filter(Vertex.start > Point(2, 2)).all()*

Re: [sqlalchemy] Can’t make the Composite Comparator work…

2022-09-16 Thread Simon King
(I haven't used any of these features, so the following is just a guess) In your assertion, you are comparing two *Point instances*. The SQLAlchemy comparator_factory mechanism has not made any changes to the Point class itself, and Point doesn't define __gt__, hence your TypeError. The point of

[sqlalchemy] Can’t make the Composite Comparator work…

2022-09-16 Thread jens.t...@gmail.com
Hello, I’m noodling through the Composite Column Types examples, and can’t make it work. Based on the code on that page I put together a minimal, reproducible example

Re: [sqlalchemy] SQLAlchemy 2. psycopg3 type adapt

2022-09-11 Thread Mike Bayer
oh, I though you were asking how to use psycopg's API. If you want to use SQLAlchemy techniques, you would use TypeDecorator: https://docs.sqlalchemy.org/en/14/core/custom_types.html#augmenting-existing-types your type would look just like

Re: [sqlalchemy] SQLAlchemy 2. psycopg3 type adapt

2022-09-11 Thread sector119
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, Mike Bayer: > maybe email on the psycopg2 list / github tracker > > On Sat, Sep 10, 2022, at

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:

[sqlalchemy] SQLAlchemy 2. psycopg3 type adapt

2022-09-10 Thread sector119
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: AUTO) I'm trying to adapt it with code below, but it looks like a bit comprehensive. Maybe you can suggest

[sqlalchemy] SqlAlchemy

2022-09-08 Thread hush Lee
I have a question about sqlalchmy is there someone help me fix it I wanner get the metadata of oracle self._db_meta.reflect(bind=self._engine, schema=self._schema) there is the log SAWarning: Did not recognize type 'LONG RAW' of column 'test_table' self._db_meta.reflect(bind=self._engine,

Re: [sqlalchemy] Re: testing patterns with sqlalchemy 2.0

2022-09-02 Thread Jonathan Vanasco
> When taking this approach, how do you ensure the accumulated schema migrations end up with a database that matches the one that create_all gives you? Sadly, I don't. I've actually been working on a test to ensure every table and column in the model exists in the database! > Creating a

Re: [sqlalchemy] Re: testing patterns with sqlalchemy 2.0

2022-09-02 Thread Elmer de Looff
On Fri, Sep 2, 2022, 08:47 Chris Withers wrote: > On 01/09/2022 20:00, Jonathan Vanasco wrote: > > > > > Create an empty schema from the models using create_all? > > > > This is what I usually do with smaller projects. > > When taking this approach, how do you ensure the accumulated schema >

Re: [sqlalchemy] Re: testing patterns with sqlalchemy 2.0

2022-09-02 Thread Chris Withers
On 01/09/2022 20:00, Jonathan Vanasco wrote: > Create an empty schema from the models using create_all? This is what I usually do with smaller projects. When taking this approach, how do you ensure the accumulated schema migrations end up with a database that matches the one that

[sqlalchemy] Re: testing patterns with sqlalchemy 2.0

2022-09-01 Thread Jonathan Vanasco
> Create an empty schema from the models using create_all? This is what I usually do with smaller projects. On some large legacy projects, I use a database dump that is loaded into Postgres - as they often rely on a lot of records that need to be in the database and generating them via

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

2022-08-31 Thread Mike Bayer
absolutely, there's no reason str | None shouldn't work also On Wed, Aug 31, 2022, at 8:26 PM, Peter Schutt wrote: > Thanks Mike, I will submit at next opportunity. > > I believe Union[str, None] is fine, just that pep 604 brought in UnionType in > 3.10+ which represents the "str | None" union

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

2022-08-31 Thread Peter Schutt
Thanks Mike, I will submit at next opportunity. I believe Union[str, None] is fine, just that pep 604 brought in UnionType in 3.10+ which represents the "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

[sqlalchemy] testing patterns with sqlalchemy 2.0

2022-08-31 Thread Chris Withers
Hi All, Are there any libraries (or anything in sqlalchemy itself!) that cover the pattern of running unit tests in against a database such that each test gets its own sterile environment in which to run? Postgres, if it helps. I've done some stuff with running in a subtransaction and rolling

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

[sqlalchemy] Using Mapped[str | None]

2022-08-31 Thread Peter Schutt
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 been able to get it to work with a couple of mods in util.typing and

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

2022-08-29 Thread Evgenii
What I’m doing wrong? class ModelObjectTable(BaseTable, BaseOwner): __tablename__ = 'model_object' model_id = Column(Integer, ForeignKey('model.id', ondelete='cascade')) # other columns model = relationship('ModelTable', uselist=False, lazy='joined',

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

2022-08-24 Thread Mike Bayer
On Wed, Aug 24, 2022, at 6:32 AM, Evgenii wrote: > > Thank you one more time! > Just in case I leave fixed expression here: > > `session.execute( >select(Instance).where(Instance.id.in([list_of_ids])), > execution_options={"populate_existing": True} > ) ` > Is there any way to set

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

2022-08-24 Thread Evgenii
Thank you one more time! Just in case I leave fixed expression here: session.execute( select(Instance).where(Instance.id.in([list_of_ids])), execution_options={"populate_existing": True} ) Is there any way to set populate_existing = True for engine or sessionmaker? ​ вторник, 23 августа

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

2022-08-23 Thread 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 > it would be nice to use: > > `session.refresh(instances_list) ` > that make a single query to database. Instead of: > do this:

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

2022-08-23 Thread Evgenii
Thanks a lot! I used “vectorized” for sqlalchemy.orm.Session.refresh method and mean that it would be nice to use: session.refresh(instances_list) that make a single query to database. Instead of: for el in instances_list: session.refresh(el) that make N queries. like: res =

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

2022-08-23 Thread Geert Jan Talens
For my purposes I'm perfectly happy to use pymysql instead of mysqldb, but I'll gladly help with further debugging if you wish to chase this down. Here's the output for the python session: Python 3.9.7 (default, Sep 16 2021, 13:09:58) [GCC 7.5.0] :: Anaconda, Inc. on linux Type "help",

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
okey doke let's see what mysql client library you are running, here's a Python session that locates the .so file in use and then runs the ldd command, which can give us a clue what you are running, if pymysql has no issue then we need to suspect client library as a possible factor. $ python

[sqlalchemy] How to Warm Up Connection Pool ?

2022-08-23 Thread mkmo...@gmail.com
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 up, or pre create, the connections in the pool? When I start my server, the

[sqlalchemy] Non-repeatable reads, vectorized refresh

2022-08-23 Thread Evgenii
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) The problem is that second query returns instance from identity_map. I know how

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

2022-08-23 Thread Geert Jan Talens
It does 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 2022 at 12:05:24 UTC-4

[sqlalchemy] Re: Filling up a field in a database from a text file, flask

2022-08-23 Thread Siarhei Siarhei
It's not Flash, but it's close.. https://github.com/wnesbv/starlette-admin-auth-blog-booking/blob/main/item/schedule_export_csv.py https://github.com/wnesbv/starlette-admin-auth-blog-booking/blob/main/item/schedule_import_csv.py понедельник, 22 августа 2022 г. в 18:00:48 UTC+3, Jonathan Vanasco:

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 initializer, then the

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

2022-08-23 Thread Mike Bayer
it happens every time the program is run? there's nothing really going on in the program here, if I take out the initializer, then the program produces lots of stack traces as expected, but even then not the "server has gone away" error. can you try running on a different MySQL /MariaDB

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

2022-08-23 Thread Geert Jan Talens
Hello Mike, Thank you for your reply. The traceback of the issue is below. I'm using sqlalchemy 1.4.40 and MySQLdb 2.1.1, the problem does not occur when using sqlite for the database instead. Regards, Geert Jan Traceback (most recent call last): File

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

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

2022-08-22 Thread Geert Jan Talens
Hi, I am trying to perform some database actions after multiprocessing some database manipulations but in most cases I get: sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2006, 'MySQL server has gone away') The code below is a working example of the problem I'm

[sqlalchemy] Re: Filling up a field in a database from a text file, flask

2022-08-22 Thread 'Jonathan Vanasco' via sqlalchemy
You should ask this in a Flask discussion group or stackoverflow. This is a sqlalchemy group and most users here have no experience with Flask. On Friday, August 19, 2022 at 4:13:50 PM UTC-4 nand...@gmail.com wrote: > I am trying to fill up a field in a table database with contents of a text

[sqlalchemy] Filling up a field in a database from a text file, flask

2022-08-19 Thread Nancy Andeyo
I am trying to fill up a field in a table database with contents of a text file, but get None as the response when I run the code. Any assistance will be appreciated. Here is my code: # view function - routes.py ... @app.route('/add_vlans', methods = ['GET', 'POST']) @login_required def

Re: [sqlalchemy] Relationships between different databases?

2022-08-17 Thread Carl Brewer
On 17/08/2022 11:22 pm, Mike Bayer wrote: 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

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

2022-08-17 Thread Adderus Berg
Good afternoon Mike I am so grateful for your guidance, time and help. I got it working, I am so glad. Kind regards On Tue, Aug 16, 2022 at 3:22 PM Mike Bayer wrote: > There is no automatic or implied coordination against the survey_answer > table as indicated in the "secondary" field. You

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] Relationships between different databases?

2022-08-17 Thread Carl Brewer
On 17/08/2022 10:31 pm, Philip Semanchuk wrote: Hi Carl, I have no experience with this so I might be making a poor suggestion, but Postgres’ foreign data wrappers might help you. They can expose the schema of other databases, so your Postgres database could be the host for all three

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