[sqlalchemy] Re: Calculate rank of single row using subquery

2021-09-14 Thread 'Jonathan Vanasco' via sqlalchemy
> Is this the most efficient way to do this, or am I over-complicating it? That roughly looks like code that I've implemented in the past. If it works and you don't have issues, I wouldn't worry about efficiency. Stuff like this will often vary based on the underlying table data - the

[sqlalchemy] Re: AsyncEngine always returns UTC time for datetime column

2021-09-14 Thread 'Jonathan Vanasco' via sqlalchemy
Can you share the database drivers / dialects you use? The discrepancy could be there. On Tuesday, September 14, 2021 at 7:03:27 AM UTC-4 ivan.ran...@themeanalytics.com wrote: > Hi all, > > I am trying to figure it out why AsyncEngine always returns UTC time for > datetime column, any help is

[sqlalchemy] AsyncEngine always returns UTC time for datetime column

2021-09-14 Thread Ivan Randjelovic
Hi all, I am trying to figure it out why AsyncEngine always returns UTC time for datetime column, any help is appreciated? I am working with sqlalchemy core and async engine. Column definition: *Column('test', DateTime(timezone=True), nullable=False)* Also tried with this, but no luck:

[sqlalchemy] 4D database and SQLAlchemy

2021-09-13 Thread Prachi Jain
Hi, I am new to SQLAlchemy as well as 4D. I am trying to write a dialect for 4D database (it is a relational database) to work with SQLAlchemy but I have run into many errors. I have tried to write my code on the basis of existing sqlalchemy-access dialect as well as looked at existing

[sqlalchemy] Re: Generic ODBC connection (4D anyone?)

2021-09-13 Thread Prachi Jain
Hi, I am wondering if you were able to write the 4D dialect? I am in a similar predicament and will appreciate if you can help me in any way to write a dialect for 4D. Thanks, Prachi On Friday, 19 February 2010 at 19:17:23 UTC James wrote: > Anyone heard of 4D? Probably not, but I would love

Re: [sqlalchemy] Selectinload and bindparam

2021-09-10 Thread Tomas Pavlovsky
Yeah, new api is great, eg: loader_fn = self.lazy_loader_map.get(relation_attribute.prop.lazy, 'selectinload') self.opts.append(loader_fn(relation_attribute.and_(*relation_filter).options(*related.opts)) or with_loader_criteria and events you mentioned. Thanks again. Have a nice weekend.

Re: [sqlalchemy] Selectinload and bindparam

2021-09-10 Thread Mike Bayer
great, glad you were able to work that out that's a lot of new API to learn On Fri, Sep 10, 2021, at 3:39 AM, Tomas Pavlovsky wrote: > Thank you very much, > It helped me a lot, UserDefinedOption and do_orm_execute, I missed it in the > documentation > > P.S. Thank you for sqlalchemy, it's

Re: [sqlalchemy] Selectinload and bindparam

2021-09-10 Thread Tomas Pavlovsky
Thank you very much, It helped me a lot, UserDefinedOption and do_orm_execute, I missed it in the documentation P.S. Thank you for sqlalchemy, it's really helpful and thanks to nested options it's really fun to use. wtorek, 31 sierpnia 2021 o 16:41:07 UTC+2 Mike Bayer napisał(a): > > this is

Re: [sqlalchemy] Change in before_flush (maybe from 1.3 to 1.4?)

2021-09-09 Thread 'Jonathan Vanasco' via sqlalchemy
What version of 1.4 are you using? It is before 1.4.7? If so, please update to the latest (1.4.23 is current) There was a regression in some early 1.4s that affected flush/commit/transaction in some situations. That was solved in 1.4.7. On Thursday, September 9, 2021 at 8:52:59 AM UTC-4 Mike

Re: [sqlalchemy] Change in before_flush (maybe from 1.3 to 1.4?)

2021-09-09 Thread Mike Bayer
On Sun, Sep 5, 2021, at 6:41 PM, and...@acooke.org wrote: > > I'm having a hard time understanding some of my own code, which no longer > works. The only way I can see it having worked in the past is if > auto-flushing did not call before_flush, but commit did? Is that possible?

[sqlalchemy] Calculate rank of single row using subquery

2021-09-09 Thread Stephan Hügel
I'm trying to calculate the rank of a particular (unique) row id by using a subquery: I first calculate the total ranking for a table, Game (using 1.4.23): sq = ( session.query( Game.id, Game.score,

[sqlalchemy] Change in before_flush (maybe from 1.3 to 1.4?)

2021-09-05 Thread and...@acooke.org
I'm having a hard time understanding some of my own code, which no longer works. The only way I can see it having worked in the past is if auto-flushing did not call before_flush, but commit did? Is that possible? Somehow I was managing to create instances (in Python) and populate them with

Re: [sqlalchemy] Can `sqlalchemy.orm.validates` be set on multiple attributes?

2021-09-04 Thread Mike Bayer
On Fri, Sep 3, 2021, at 4:07 PM, niuji...@gmail.com wrote: > In the official documentation it says: > > > *validates* > (*names, > **kw) > > > Decorate a method as a ‘validator’ for one or more named

[sqlalchemy] Re: How to filter SQLAlchemy JSON column containing array of dicts by dict attribute

2021-09-03 Thread Joseph Baniqued
It's just a simple syntax issue in Boncheff's query. in_ takes a list so it should be: *session.query(MyModel).filter(MyModel.foo[0]['tags'].in_(['test_tag1'])).all()* On Tuesday, November 27, 2018 at 11:55:57 AM UTC-8 himanshu jain wrote: > How did you get it working? > can you give an

[sqlalchemy] Can `sqlalchemy.orm.validates` be set on multiple attributes?

2021-09-03 Thread niuji...@gmail.com
In the official documentation it says: validates (*names, **kw) Decorate a method as a ‘validator’ for one or more named properties. I need to validate two incoming *-**attributes at the same time, for

Re: [sqlalchemy] Issue with mypy and the new version of alembic (1.7.1 agaist 1.6.5)

2021-09-03 Thread Stéphane Brunner
OK, thanks for the information :-) Le Thursday, September 2, 2021 à 3:45:45 PM UTC+2, Mike Bayer a écrit : > this is issue https://github.com/sqlalchemy/alembic/issues/897 and we > don't know how to fix it. suggestions welcome. > > > > On Thu, Sep 2, 2021, at 3:32 AM, Stéphane Brunner wrote: >

Re: [sqlalchemy] Issue with mypy and the new version of alembic (1.7.1 agaist 1.6.5)

2021-09-02 Thread Mike Bayer
this is issue https://github.com/sqlalchemy/alembic/issues/897 and we don't know how to fix it. suggestions welcome. On Thu, Sep 2, 2021, at 3:32 AM, Stéphane Brunner wrote: > Hello, > > In the new version, I get the following error with my mypy check: > > > > Traceback (most recent call

[sqlalchemy] Issue with mypy and the new version of alembic (1.7.1 agaist 1.6.5)

2021-09-02 Thread Stéphane Brunner
Hello, In the new version, I get the following error with my mypy check: Traceback (most recent call last): File "/usr/local/bin/prospector", line 8, in sys.exit(main()) File "/usr/local/lib/python3.8/dist-packages/prospector/run.py", line 181, in main prospector.execute() File

Re: [sqlalchemy] ORM query returning separate columns instead of objects

2021-09-01 Thread Mike Bayer
you can take the statement and execute it on the connection instead, then you'll get tuples with columns. not sure if there was some way to get this through session.execute() directly. On Tue, Aug 31, 2021, at 5:01 PM, Gord Thompson wrote: > My memory is failing me. I seem to recall that

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-09-01 Thread Mike Bayer
this is then the diffeence between tuples and dicts call pandas like this: DataFrame(result.mappings()) that will give it a series of dicts rather than tuples for rows On Wed, Sep 1, 2021, at 8:04 AM, Gord Thompson wrote: > Another workaround would be … > > df =

Re: [sqlalchemy] SqlAlchemy 1.4 and Sequences

2021-09-01 Thread Mike Bayer
please upgrade to the most recent psycopg2 On Wed, Sep 1, 2021, at 6:12 AM, Francesca L wrote: > Thank you very much for your quick help. > > Yes, you are right, I was using the: "implicit_returning=False" flag on my > "create_engine()". > > I add the following, in case it can be useful to

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-09-01 Thread Gord Thompson
Another workaround would be … df = pd.read_sql_query(select(User.id, User.name), engine) print(df) """ id name 0 1 Gord 1 2 Bob """ … although it does produce a couple of RemovedIn20Warning messages (that will probably be resolved once pandas does SQLA 1.4 better). On Wednesday,

Re: [sqlalchemy] SqlAlchemy 1.4 and Sequences

2021-09-01 Thread Francesca L
Thank you very much for your quick help. Yes, you are right, I was using the: "implicit_returning=False" flag on my "create_engine()". I add the following, in case it can be useful to you: I removed the flag as suggested, and that's what I get now for the same code example (with sqlalchemy

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-09-01 Thread Terrence-Monroe: Brannon
Just for completeness I'm linking to source code to reproduce the problem: play/sqlalchemy-and-pandas at main · metaperl/play (github.com) Looks like the 1.4 release of pandas will remedy this problem. On Wednesday, September

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-09-01 Thread Federico Caselli
Hi, This is a pandas bug, not an sqlalchemy ones. It was already reported here https://github.com/pandas-dev/pandas/issues/40682 On Tuesday, 31 August 2021 at 23:15:04 UTC+2 Gord Thompson wrote: > *With version 1.3:* > > Base = declarative_base() > > > class User(Base): > __tablename__ =

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-08-31 Thread Gord Thompson
*With version 1.3:* Base = declarative_base() class User(Base): __tablename__ = "user" id = Column(Integer, primary_key=True) name = Column(String) Base.metadata.create_all(engine) print(pd.__version__) # 1.3.2 print(sa.__version__) # 1.3.24 session = Session(engine)

[sqlalchemy] ORM query returning separate columns instead of objects

2021-08-31 Thread Gord Thompson
My memory is failing me. I seem to recall that there was a succinct way to get a 1.4/2.0 ORM query to return individual columns instead of ORM objects. That is, to tell this print(session.execute(select(User)).fetchall()) # [(<__main__.User object at 0x0090175EC700>,)] to return the

Re: [sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-08-31 Thread Mike Bayer
On Tue, Aug 31, 2021, at 3:10 PM, Terrence-Monroe: Brannon wrote: > > Creating a pandas dataframe that contained descriptive column names formerly > was as easy as: > > result_set = session.query(cls.column_1) > df = pandas.Dataframe(result_set) > print df.column_1 > > but while this works

[sqlalchemy] Re: Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-08-31 Thread Gord Thompson
One option would be to replace result_set = session.query(cls.column_1) with result_set = session.execute(select(cls.column_1)).mappings().all() On Tuesday, August 31, 2021 at 1:10:17 PM UTC-6 thequie...@gmail.com wrote: > > Creating a pandas dataframe that contained descriptive column names

[sqlalchemy] Why was the column information stripped away in SA 1.4.20 that existed in 1.3.20?

2021-08-31 Thread Terrence-Monroe: Brannon
Creating a pandas dataframe that contained descriptive column names formerly was as easy as: result_set = session.query(cls.column_1) df = pandas.Dataframe(result_set) print df.column_1 but while this works in 1.3.20, in later versions of SA such as 1.4.19, there is not enough column info

Re: [sqlalchemy] Using SQLAlchemy to check if column is in numeric ranges

2021-08-31 Thread Simon King
You want a combination of the "between" function/method: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.between ...and the "or_" function: https://docs.sqlalchemy.org/en/14/core/sqlelement.html#sqlalchemy.sql.expression.or_ Something like this: ranges = [(18,

Re: [sqlalchemy] Selectinload and bindparam

2021-08-31 Thread Mike Bayer
this is true, the parameters can't be known to be passed along to a secondary query. the approach here would require that you make careful use of custom user options and events in order to make it work. the general event hook you would use is documented at

Re: [sqlalchemy] SqlAlchemy 1.4 and Sequences

2021-08-31 Thread Mike Bayer
issue https://github.com/sqlalchemy/sqlalchemy/issues/6963 is added to deal with possibly multiple failure modes in this case. On Tue, Aug 31, 2021, at 10:24 AM, Mike Bayer wrote: > Hi - > > Your test case is omitting a critical detail which we would assume is you are > using the

Re: [sqlalchemy] SqlAlchemy 1.4 and Sequences

2021-08-31 Thread Mike Bayer
Hi - Your test case is omitting a critical detail which we would assume is you are using the "implicit_returning=False" flag on your create_engine().dont use this flag as it serves no useful purpose and that will fix your issue here, we will be deprecating and removing this flag. will try

[sqlalchemy] Using SQLAlchemy to check if column is in numeric ranges

2021-08-31 Thread chat...@gmail.com
Hello All!! , I have a list of age ranges i.e 18-25, 40-55 and more how can I make make a query using *SQLAlchemy* that will check if a Column is in ranges [18,25] OR [40-55] OR [60-70] Regards,Christos -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

Re: [sqlalchemy] Selectinload and bindparam

2021-08-31 Thread Tomas Pavlovsky
Sorry, once again :) class X(Base): id: int = Column('x_id', Integer, primary_key=True, autoincrement=True) a_id: int = Column('a_id', Integer, ForeignKey('a.a_id')) a = relationship(A) s = select(A).where(A.id == 1) s = s.options(joinedload(A.b_filtered_rel)) or s =

Re: [sqlalchemy] Selectinload and bindparam

2021-08-31 Thread Tomas Pavlovsky
Hello Mike, Thank you very much for your response. I ended up with that, but i wanna ask you about this solution. class A(Base): id: int = Column('a_id', Integer, primary_key=True, autoincrement=True) #descr class B(Base): id: int = Column('b_id', Integer, primary_key=True,

[sqlalchemy] SqlAlchemy 1.4 and Sequences

2021-08-31 Thread Francesca L
Hi group, I am tring to migrate from version *1.3.24* to *1.4.23* of SqlAlchemy, using *PostgreSQL 10*. I found that the following code example works with 1.3, but triggers a traceback with 1.4. import sqlalchemy session = ... metadata = sqlalchemy.MetaData() s_items =

Re: [sqlalchemy] Selectinload and bindparam

2021-08-30 Thread Mike Bayer
yes, you would use bindparam("some_name") in conjunction with the "and_()" feature, like options(selectinload(MyClass.foo.and_(MyClass.name == bindparam("some_name" On Mon, Aug 30, 2021, at 10:55 AM, Tomas Pavlovsky wrote: > Hello, > > is it possible in sqlalchemy arguments from

[sqlalchemy] Selectinload and bindparam

2021-08-30 Thread Tomas Pavlovsky
Hello, is it possible in sqlalchemy arguments from db.execute(query, args) to be passed to query emitted by selectinload? Thanks, Tomas -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal,

Re: alembic upgrade heads

2021-08-25 Thread Mike Bayer
seems like you should ensure that Alembic is installed in the current Python environment. looks like it is not installed correctly. On Wed, Aug 25, 2021, at 2:23 PM, Vinod Rao wrote: > Hi all: > > I have been struggling to solve the following error: > > File "/virtual_env/bin/alembic",

alembic upgrade heads

2021-08-25 Thread Vinod Rao
Hi all: I have been struggling to solve the following error: File "/virtual_env/bin/alembic", line 5, in from alembic.config import main ModuleNotFoundError: No module named 'alembic.config' Please let me know if any resolution on it. Thanks. Regards, Vinod Rao -- You received this

Re: [sqlalchemy] Combination of (pg) on_conflict_do_update and ORM's bulk_insert_mappings

2021-08-25 Thread Anthony Catel
Hey Mike, Thanks for the quick reply! I already tried to pass a mapped class to Insert() but it didn't work (because the mapper is joined-inheritance and so it needs to insert a row in both the Base parent table and the child table). Got an error about "Unconsumed column names", because the

Re: [sqlalchemy] Combination of (pg) on_conflict_do_update and ORM's bulk_insert_mappings

2021-08-24 Thread Mike Bayer
not exactly what you asked for but this seems pretty easy to use: https://docs.sqlalchemy.org/en/14/orm/persistence_techniques.html#using-postgresql-on-conflict-with-returning-to-return-upserted-orm-objects On Tue, Aug 24, 2021, at 2:53 PM, Mike Bayer wrote: > let me try to make an example >

Re: [sqlalchemy] Combination of (pg) on_conflict_do_update and ORM's bulk_insert_mappings

2021-08-24 Thread Mike Bayer
let me try to make an example On Tue, Aug 24, 2021, at 1:36 PM, Mike Bayer wrote: > you can use a mapped class directly with pg's insert() construct: > > insert(MyClass).values(...).on_conflict(...) > > are you referring to being able to pass instances of mapped objects to the > values? Just

Re: [sqlalchemy] Combination of (pg) on_conflict_do_update and ORM's bulk_insert_mappings

2021-08-24 Thread Mike Bayer
you can use a mapped class directly with pg's insert() construct: insert(MyClass).values(...).on_conflict(...) are you referring to being able to pass instances of mapped objects to the values? Just pull these out of each object's `__dict__`, it's much more efficient than

[sqlalchemy] Combination of (pg) on_conflict_do_update and ORM's bulk_insert_mappings

2021-08-24 Thread Anthony Catel
Hey, I'm looking for a way to builk upsert using pg's "on_conflict_do_update" in a way that would allow me to use a mapper classe (because the objects I want to insert/update are joined-inheritance). bulk_insert_mappings() would allow me to use its "return_defaults" and to provide a Mapper

Re: [sqlalchemy] Configuring Alembic in SQL-only mode

2021-08-22 Thread Mike Bayer
it should be fine though I'm surprised PostgreSQL isn't forcing you to ROLLBACK the transaction when one of those operations fails.if it isn't then should be fine for now. I'd probably make a function that does the command execution that you import from somewhere else though, that way your

[sqlalchemy] Configuring Alembic in SQL-only mode

2021-08-21 Thread zsol...@gmail.com
Hi, I'm using SQLAlchemy 1.3 with PostgreSQL. I'm trying to use alembic in SQL-only mode. I'm using a custom sql-diff script which takes the pg_dump's --schema output and compares it with a clean db setup's one and tells me exactly what changes do I need to make. This way I catch 100% of the

[sqlalchemy] Re: sqlite setting foreign_keys=off temporarily

2021-08-10 Thread 'Jonathan Vanasco' via sqlalchemy
The first two things I would look into: 1. Check the sqlite install/version that SqlAlchemy uses. It is often NOT the same as the basic operating system install invoked in your terminal. Sometimes that version does not have the functionality you need. 2. Check the transactional isolation

Re: [sqlalchemy] Join multiple tables with association tables

2021-08-10 Thread 'timbecks' via sqlalchemy
*Is the relationship between Fact and Info meant to be many-to-many? And likewise the relationship between Text and Info?* You are right about that. Your code did exactly what I wanted. Thank you so much! I figured it could have to do somethin with a subquery but I'm just starting

Re: [sqlalchemy] Join multiple tables with association tables

2021-08-10 Thread Simon King
It's difficult to tell from your code what your intention is. Is the relationship between Fact and Info meant to be many-to-many? And likewise the relationship between Text and Info? Forgetting SQLAlchemy for a moment, what is the SQL that you want to produce? Does the script below do what you

[sqlalchemy] Join multiple tables with association tables

2021-08-09 Thread 'timbecks' via sqlalchemy
I am trying to figure out the correct join query setup within SQLAlchemy, but I can't seem to get my head around it. I have the following table setup (simplified, I left out the non-essential fields): [image: Unbenannt.png] [image: Unbenannt2.png] The facts are associated to info, info is

[sqlalchemy] Join multiple tables with association tables

2021-08-09 Thread 'timbecks' via sqlalchemy
I am trying to figure out the correct join query setup within SQLAlchemy, but I can't seem to get my head around it. I have the following table setup (simplified, I left out the non-essential fields): ```pyhton "facts_info", Base.metadata, sqlColumn("fact_id", Integer,

[sqlalchemy] Join multiple tables with association tables

2021-08-09 Thread 'timbecks' via sqlalchemy
I am trying to figure out the correct join query setup within SQLAlchemy, but I can't seem to get my head around it. I have the following table setup (simplified, I left out the non-essential fields): ```pyhton "facts_info", Base.metadata, sqlColumn("fact_id", Integer,

[sqlalchemy] sqlite setting foreign_keys=off temporarily

2021-08-07 Thread RexE
On startup of my program, my in-memory sqlite DB needs to turn off foreign key enforcement temporarily (in order to insert data from a different sqlite DB). However, it seems my command to set foreign_keys back on has no effect. See the attached MRE. I expect this output: after turning back on

[sqlalchemy] Re: Oracle connection problem

2021-08-06 Thread 'Jonathan Vanasco' via sqlalchemy
You should ensure the connection string does not have any reserved/escape characters in it. People have had similar issues in the past. If that is the case, there are some recent threads in this group and on the github issues that show how to overcome the issue by building a connection string

[sqlalchemy] Re: update with in clause from kwargs

2021-08-05 Thread Lele Gaifax
Larry Martell writes: > I got this working by adding synchronize_session='fetch' to the > update. Really would like to know why that was needed - I have > similar code, but that does not use variables (the model and columns > are hard coded) and that works without synchronize_session. I think

Re: [sqlalchemy] Re: update with in clause from kwargs

2021-08-04 Thread Larry Martell
On Wed, Aug 4, 2021 at 6:08 PM Larry Martell wrote: > > On Wed, Aug 4, 2021 at 12:30 PM Larry Martell wrote: > > > > On Tue, Aug 3, 2021 at 11:11 PM Lele Gaifax wrote: > > > > > > Larry Martell writes: > > > > > > > I am trying to write a function that takes kwargs as a param and > > > >

Re: [sqlalchemy] Re: update with in clause from kwargs

2021-08-04 Thread Larry Martell
On Wed, Aug 4, 2021 at 12:30 PM Larry Martell wrote: > > On Tue, Aug 3, 2021 at 11:11 PM Lele Gaifax wrote: > > > > Larry Martell writes: > > > > > I am trying to write a function that takes kwargs as a param and > > > generates an update statement where the rows to be updated are > > >

[sqlalchemy] Oracle connection problem

2021-08-04 Thread jca...@gmail.com
I am using sqlalchemy 1.4.22 and cx oracle 8.2.1 to connect to production and development environments that each host a similar copy of the same schema. The connection string that I use is the same for each excluding the password: oracle+cx_oracle://user:pass@MyTNS Dev works without a

Re: [sqlalchemy] Re: update with in clause from kwargs

2021-08-04 Thread Larry Martell
On Tue, Aug 3, 2021 at 11:11 PM Lele Gaifax wrote: > > Larry Martell writes: > > > I am trying to write a function that takes kwargs as a param and > > generates an update statement where the rows to be updated are > > specified in an in clause. > > > > Something like this: > > > > def

[sqlalchemy] Re: update with in clause from kwargs

2021-08-04 Thread Lele Gaifax
Larry Martell writes: > I am trying to write a function that takes kwargs as a param and > generates an update statement where the rows to be updated are > specified in an in clause. > > Something like this: > > def update_by_in(self, **kwargs): > filter_group = [] > for col

[sqlalchemy] update with in clause from kwargs

2021-08-03 Thread Larry Martell
I am trying to write a function that takes kwargs as a param and generates an update statement where the rows to be updated are specified in an in clause. Something like this: def update_by_in(self, **kwargs): filter_group = [] for col in kwargs['query_params']: #

Re: [sqlalchemy] Re: Testing and deprecation of nested transactions

2021-08-02 Thread Federico
If you only need to support postgresql you may also create a db to be used as template, then each test gest it's own db generated from the original template db. I think this should be the fastest way of restoring the db state after a test On Mon, 2 Aug 2021, 19:24 Dejan Čabrilo, wrote: > Hi, >

[sqlalchemy] Re: Testing and deprecation of nested transactions

2021-08-02 Thread Dejan Čabrilo
Hi, >From what I see, that's only pertinent to the ORM, right? I don't use ORM, SqlAlchemy core only, so I think that wouldn't work, right? Thanks! Dejan On Saturday, July 31, 2021 at 7:41:49 AM UTC+2 cfede...@gmail.com wrote: > Hi, > > Have you tried using this pattern from the

[sqlalchemy] Re: Testing and deprecation of nested transactions

2021-08-02 Thread Dejan Čabrilo
Thanks for the suggestion! Sqlite3 won't work for my use-case because I depend on Postgresql and its extensions a lot. I ended up using this fixture: @pytest.fixture(scope='function') alembic.config.main(argv=["upgrade", "head"]) yield alembic.config.main(argv=["downgrade",

[sqlalchemy] Re: Testing and deprecation of nested transactions

2021-07-30 Thread Federico Caselli
Hi, Have you tried using this pattern from the documentation? I think you can also use that while using only connections https://docs.sqlalchemy.org/en/14/orm/session_transaction.html?highlight=after_transaction_end#joining-a-session-into-an-external-transaction-such-as-for-test-suites On

[sqlalchemy] Re: Testing and deprecation of nested transactions

2021-07-30 Thread 'Jonathan Vanasco' via sqlalchemy
I typically do local developer testing with sqlite3, and the switch the database to postgresql for build/deploy/ci testing in the cloud. For complex tests, I typically use a fresh database "image". e.g. a sqlite file or pgdump output that is tracked in git. This is not the solution you're

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread 'Jonathan Vanasco' via sqlalchemy
The second option looks perfect. Will try it! Thank you so much, Simon! On Friday, July 30, 2021 at 1:32:42 PM UTC-4 Simon King wrote: > I can think of a couple of options: > > 1. Create a TypeDecorator for String and Text columns that raises an > error if it sees a bytestring. This will only

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread Simon King
I can think of a couple of options: 1. Create a TypeDecorator for String and Text columns that raises an error if it sees a bytestring. This will only flag the error when the session is flushed. 2. Listen for mapper_configured events, iterate over the mapper properties and add an

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-30 Thread 'Jonathan Vanasco' via sqlalchemy
Mike, thanks for replying but go back to vacation. Anyone else: I am thinking more about an event that can be used to catch, perhaps log, all bytes that go in. I only use a few column classes that expect bytestrings, but many that do not. I've gotten every known bug so far, but I'd like to

[sqlalchemy] Testing and deprecation of nested transactions

2021-07-30 Thread Dejan Čabrilo
Hello everyone, I am working on a new project using SqlAlchemy Core 1.4 with Postgresql and wanted to implement the following pattern for my tests: - Before each test I would start a transaction (in a @pytest.fixture(autorun=True)) - Each test may create its own transactions - At the end of

Re: [sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-29 Thread Mike Bayer
The Unicode datatype will emit a warning if you pass it a bytestring. you can use that instead of String, or use a datatype with your own assertions based on https://docs.sqlalchemy.org/en/14/core/custom_types.html#coercing-encoded-strings-to-unicode On Thu, Jul 29, 2021, at 5:17 PM,

[sqlalchemy] prevent (raise exceptions) on bytestring values for non-byte types

2021-07-29 Thread 'Jonathan Vanasco' via sqlalchemy
I am finally at the tail end of migrating my largest (and hopefully last) Python2 application to Python3. An issue that has popped up a lot during this transition, is when a py3 bytestring gets submitted into SqlAlchemy. When that happens, it looks like SqlAlchemy just passes the value into

[sqlalchemy] Re: Relationship backref cascade path

2021-07-24 Thread Lele Gaifax
"Mike Bayer" writes: > On Sat, Jul 24, 2021, at 5:49 AM, Lele Gaifax wrote: >> Hi all, >> >> I need some clarification on the following RemovedIn20Warning >> >> "Pet" object is being merged into a Session along the backref cascade path >> for relationship "Person.pets"; in SQLAlchemy 2.0,

Re: [sqlalchemy] Relationship backref cascade path

2021-07-24 Thread Mike Bayer
On Sat, Jul 24, 2021, at 5:49 AM, Lele Gaifax wrote: > Hi all, > > I need some clarification on the following RemovedIn20Warning > > "Pet" object is being merged into a Session along the backref cascade path > for relationship "Person.pets"; in SQLAlchemy 2.0, this reverse cascade will >

[sqlalchemy] Relationship backref cascade path

2021-07-24 Thread Lele Gaifax
Hi all, I need some clarification on the following RemovedIn20Warning "Pet" object is being merged into a Session along the backref cascade path for relationship "Person.pets"; in SQLAlchemy 2.0, this reverse cascade will not take place... Does it really means that in SA 2.0 the pattern

Re: [sqlalchemy] async mode and relationship more than one level deep

2021-07-22 Thread sector119
Thank You, works like a charm четверг, 22 июля 2021 г. в 00:26:57 UTC+3, Mike Bayer: > you need to chain those like: > > selectinload(Database.person).selectinload(Person.city) > > docs: > > >

[sqlalchemy] Re: joinedload().load_only() emits 2.0 warning

2021-07-21 Thread Lele Gaifax
Federico Caselli writes: > Updated here https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2959 Great, thank you! ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. l...@metapensiero.it |

Re: [sqlalchemy] async mode and relationship more than one level deep

2021-07-21 Thread Mike Bayer
you need to chain those like: selectinload(Database.person).selectinload(Person.city) docs: https://docs.sqlalchemy.org/en/14/orm/loading_relationships.html#relationship-loading-with-loader-options On Wed, Jul 21, 2021, at 4:25 PM, sector119 wrote: > Hello, Mike > > When I want to use some

[sqlalchemy] Re: async mode and relationship more than one level deep

2021-07-21 Thread sector119
s = select( Database ).options( selectinload( Database.person ).options( joinedload(Person.city) ) ) среда, 21 июля 2021 г. в 23:25:05 UTC+3, sector119: > Hello, Mike > > When I want to use some relationship I just set selectinload option on it > like > > s =

[sqlalchemy] async mode and relationship more than one level deep

2021-07-21 Thread sector119
Hello, Mike When I want to use some relationship I just set selectinload option on it like s = select(Database).options(selectinload(Database.person)) Here Database.person is relationship with Person model But what to do if I want to access some relationship of Person model? For example

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-20 Thread Mike Bayer
On Tue, Jul 20, 2021, at 10:00 AM, Evgenii wrote: > As it was mentioned before, I create repeated elements in relationship > deliberately. Assuming this implies the table can have no candidate key, this is an antipattern in SQL and there are lots of answers/articles/etc on the web why all

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-20 Thread Evgenii
As it was mentioned before, I create repeated elements in relationship deliberately. Moreover, alchemy allows me to do that, but it fails during deleting instances and modifying relationships. Unfortunately, this is not that case, where I can start all over again. All examples are maximally

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-20 Thread Mike Bayer
if you are mapping ORM classes to the same table that is also used as the "secondary" table in a relationship() that can lead to the ORM inserting more than one row for that table. based on the name "foo_bar" I would imagine something like this might be going on. > > Pls tell how to

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-20 Thread Evgenii
Mike, thank you for the answer. But I have another problem with deleting the instance. Even though all instances belong to the same session (it is possible to push foo instance): with Session() as session: b1 = session.query(BarTable).get(1) b2 = session.query(BarTable).get(1) foo

[sqlalchemy] Re: joinedload().load_only() emits 2.0 warning

2021-07-20 Thread Federico Caselli
Updated here https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2959 On Friday, 16 July 2021 at 14:00:33 UTC+2 leleg...@gmail.com wrote: > Federico Caselli writes: > > > There is no difference, it's the documentation that's outdated. > > > > We should update that > > I see, thank you for

[sqlalchemy] Announcing API Logic Server

2021-07-19 Thread Val Huber
You may be interested in ApiLogicServer , open source on Git. With 1 command, it creates a customizable project providing a JSON:API, and a Basic Web App. These are based on SQLAlchemy, so it uses sqlacodegen to create your model classes.

Re: [sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-19 Thread Mike Bayer
This is all expected behavior, the main reason you're having problems is that you are using multiple sessions and mixing their results together.If you need to do this, there are few approaches, the most basic being to use the merge() method:

[sqlalchemy] sqlalchemy.exc.InvalidRequestError: Can't attach instance another instance with key is already present in this session

2021-07-19 Thread Evgenii
Hello! I’m using many-to-many relation, and this relationship bar_list must have list of instances. Some of them can be repeated (ex. [inst1, inst2, inst1]). I attach very simplified code there (all of database interaction is hidden under the hood, user accesses database at top level, but this

[sqlalchemy] Re: sqlacodegen bug ?

2021-07-17 Thread 'Sebastian Cheung' via sqlalchemy
Also, why only public.* tables are generated in my case, but all non-public.* tables are not generated? On Thursday, June 15, 2017 at 4:30:45 AM UTC+1 Kevin Ernst wrote: > Hi Jean-Luc, > > I wish I'd seen your post earlier, I could've helped. :) I had this exact > same problem today, found

[sqlalchemy] Re: joinedload().load_only() emits 2.0 warning

2021-07-16 Thread Lele Gaifax
Federico Caselli writes: > There is no difference, it's the documentation that's outdated. > > We should update that I see, thank you for the clarification! ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi

[sqlalchemy] Re: joinedload().load_only() emits 2.0 warning

2021-07-16 Thread Federico Caselli
There is no difference, it's the documentation that's outdated. We should update that On Friday, 16 July 2021 at 09:22:52 UTC+2 leleg...@gmail.com wrote: > Federico Caselli writes: > > > As the warning mebtions, the issue is that you are using the string name > > with load only instead of the

[sqlalchemy] Re: joinedload().load_only() emits 2.0 warning

2021-07-16 Thread Lele Gaifax
Federico Caselli writes: > As the warning mebtions, the issue is that you are using the string name > with load only instead of the column from the class. Ok, so maybe we should explain the difference in the joinedload().load_only() documentation? As said, the sample code attached to the

Re: [sqlalchemy] joinedload().load_only() emits 2.0 warning

2021-07-16 Thread Federico Caselli
Hi. As the warning mebtions, the issue is that you are using the string name with load only instead of the column from the class. In this load only from the file: .load_only('firstname'))) On Thursday, 15 July 2021 at 14:28:29 UTC+2 Mike Bayer wrote: > i can look later, if i forget after a

Re: [sqlalchemy] joinedload().load_only() emits 2.0 warning

2021-07-15 Thread Mike Bayer
i can look later, if i forget after a day or so please post this to github discussions and/or issues where i will notice it better On Thu, Jul 15, 2021, at 7:44 AM, Lele Gaifax wrote: > Hi, > > while upgrading one of my apps to SA 1.4, paying attention toward 2.0 > compatibility, I found one

[sqlalchemy] joinedload().load_only() emits 2.0 warning

2021-07-15 Thread Lele Gaifax
Hi, while upgrading one of my apps to SA 1.4, paying attention toward 2.0 compatibility, I found one single issue that I was not able to figure out whether I'm doing something wrong or missed something in the excellent migration guide. All tests pass, but executing them with SQLALCHEMY_WARN_20 I

Re: [sqlalchemy] traceback with dict-polymorphic example

2021-07-14 Thread I Jenkins
Awesome that seems to fix it. Thanks Mike! On Wednesday, July 14, 2021 at 8:00:08 PM UTC-7 Mike Bayer wrote: > fixed in master, please apply this patch: > > diff --git a/examples/vertical/dictlike-polymorphic.py > b/examples/vertical/dictlike-polymorphic.py > index 23a6e093d9..4c81af6d54 100644

Re: [sqlalchemy] traceback with dict-polymorphic example

2021-07-14 Thread Mike Bayer
fixed in master, please apply this patch: diff --git a/examples/vertical/dictlike-polymorphic.py b/examples/vertical/dictlike-polymorphic.py index 23a6e093d9..4c81af6d54 100644 --- a/examples/vertical/dictlike-polymorphic.py +++ b/examples/vertical/dictlike-polymorphic.py @@ -83,7 +83,7 @@ class

<    5   6   7   8   9   10   11   12   13   14   >