[sqlalchemy] Re: many-to-many orm warnings

2022-03-09 Thread Michael Merickel
Sorry for the rambling, it's been difficult for me to figure out what question to ask because I'm so confused. Below is the minimum viable example that produces no warnings with respect to the overlaps flags and I cannot explain hardly any of them. For example, why does Child.parents require

[sqlalchemy] Re: many-to-many orm warnings

2022-03-09 Thread Michael Merickel
I think ultimately I want the overlaps config but reading through https://docs.sqlalchemy.org/en/14/errors.html#relationship-x-will-copy-column-q-to-column-p-which-conflicts-with-relationship-s-y it doesn't make any sense to me what the values in the overlaps= argument are referring to. For

[sqlalchemy] Re: many-to-many orm warnings

2022-03-09 Thread Michael Merickel
It's probably worth noting I can narrow it down to a single warning with the following snippet and it's still unclear to me how to resolve this: class Association(Base): __tablename__ = 'association' left_id = Column(ForeignKey('left.id'), primary_key=True) right_id =

[sqlalchemy] many-to-many orm warnings

2022-03-09 Thread Michael Merickel
I have looked at the couple examples in the docs (many-to-many, and association table) and have noticed that my codebase has a slightly different pattern which is causing warnings when upgrading to 1.4. I'm trying to figure out the best pattern to accomplish what I've been doing which doesn't

[sqlalchemy] Idiomatic way to track state during ETL processing

2022-02-28 Thread Andrew Martin
I haven't found any topics here that address this, so it may mean that the answer is so simple that I'm just overthinking here. Context: I'm the lone developer on a new tech team at a company that's never had any team in place before. Everything is greenfield. Which is great because I get to

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-25 Thread janio mendonca junior
Hi Simon, Thank you for your explanation. I managed to create the table by using df.to_sql. My mistake was because I was using a serie to sql instead of a dataframe. On Fri, Feb 25, 2022 at 5:33 AM Simon King wrote: > I don't know enough about Pandas to explain your error, but I did >

Re: [sqlalchemy] Issue "translating" raw SQL to SQLAlchemy ORM query

2022-02-25 Thread Simon King
By default, relationship loading is deliberately not affected by your join conditions. If you want a relationship property to be restricted to the rows you've selected in your query, you need to use the "contains_eager()" query option:

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-25 Thread Simon King
I don't know enough about Pandas to explain your error, but I did notice that the SQL that is failing is trying to insert into a table called "mlstreb", but elsewhere in your code you refer to "mls_treb". Could that be part of the problem? To define a table from your CSV file, you could do

Re: [sqlalchemy] Async Event Listeners

2022-02-24 Thread Mike Bayer
the error seems like what would happen right now, sure. we have a complete doc section now on setting up event handlers with async objects: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html#using-events-with-the-asyncio-extension On Thu, Feb 24, 2022, at 2:56 PM, Brendan

[sqlalchemy] Async Event Listeners

2022-02-24 Thread Brendan Blanchard
Hi all, I've been having a lot of fun trying to optimize an async data retrieval system, but am in need of tracking when connections are checked in and out so I can debug overloading the connection pool. The documentation was of course helpful in the synchronous case for adding listeners on

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-24 Thread Simon King
Before we do that, you said that you tried pandas dataframe.to_sql but it didn't work - can you explain what you mean? Did it raise an error, or produce the wrong result, or something else? Simon On Wed, Feb 23, 2022 at 9:13 PM janio mendonca junior wrote: > > Hi Simon, > > Thank you for your

Re: [sqlalchemy] Copy a dataframe to postgresql database within a schema

2022-02-23 Thread Nahum Castro
Yes, you were right. thanks. El mié, 23 feb 2022 a la(s) 13:34, Mike Bayer (mike...@zzzcomputing.com) escribió: > the "from msilib import schema" import is at the top of your script. it > looks like it's there by accident. are you using vscode? I find it often > adds random package names as

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-23 Thread janio mendonca junior
Hi Simon, Thank you for your help. I am brand new working with SQLalchemy, really appreciate if you explain how to generate the metadata with the list of column names from the .CSV to create the tables? On Wed, Feb 23, 2022, 3:52 PM Simon King wrote: > Build a list of Column objects from the

Re: [sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-23 Thread Simon King
Build a list of Column objects from the columns in the CSV file, and use that list to create a Table: https://docs.sqlalchemy.org/en/14/core/metadata.html Once you've created the Table, you can insert data into it using the table.insert() method:

[sqlalchemy] What is the best way to declare a table with 260 columns and add rows on that table

2022-02-23 Thread janio mendonca junior
Hi all, I have a inquiry from my job to create 2 tables related one-to-one and insert some rows on the table. I have a .CSV with the data dictionary from the table and I am wondering to know how to declare the tables columns automatically without write one by one column (there are 260 columns).

Re: [sqlalchemy] Copy a dataframe to postgresql database within a schema

2022-02-23 Thread Mike Bayer
the "from msilib import schema" import is at the top of your script. it looks like it's there by accident. are you using vscode? I find it often adds random package names as it guesses from my typing. I'd remove that line. On Wed, Feb 23, 2022, at 1:54 PM, Nahum Castro wrote: > Hello All. >

[sqlalchemy] Copy a dataframe to postgresql database within a schema

2022-02-23 Thread Nahum Castro
Hello All. I have a problem when I try to load a dataframe to postgresql and store it in a schema.. from msilib import schema import pandas as pd import numpy as np import glob from sqlalchemy import create_engine from datetime import datetime, timedelta engine =

[sqlalchemy] Issue "translating" raw SQL to SQLAlchemy ORM query

2022-02-23 Thread shuhari2020
*FROM*: https://stackoverflow.com/questions/71225408/issue-translating-raw-sql-to-sqlalchemy-orm-query I have the following raw SQL statement that I am having trouble "translating" into a SQLAlchemy query: (the hardcoded value 38 is just for testing) *SELECT * FROM public.data_appquestion AS

Re: [sqlalchemy] Remove/Filter a query.all() results, add a 'virtual' column

2022-02-21 Thread Cp Divers
Hello Simon, thank you for your help. I've also done more research and tests on my side and here are my solution: 1) remove some item from the list - this was quite easy ! items_to_delete=[] # add all the row/item index that I want to delete for idx,p in enumerate(found): if not

Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-21 Thread Philip Semanchuk
> On Feb 21, 2022, at 9:50 AM, Mike Bayer wrote: > > I thought 1.3 had "values", but if not, then you'd need to roll a recipe of > some kind, the original recipe is at > https://github.com/sqlalchemy/sqlalchemy/wiki/PGValues Thanks. In 1.3 sqlalchemy.sql.expression.ValuesBase exists,

Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-21 Thread Mike Bayer
I thought 1.3 had "values", but if not, then you'd need to roll a recipe of some kind, the original recipe is at https://github.com/sqlalchemy/sqlalchemy/wiki/PGValues On Mon, Feb 21, 2022, at 9:06 AM, Philip Semanchuk wrote: > Thanks! It looks like 1.4 is required for this, correct? Any way

Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-21 Thread Philip Semanchuk
Thanks! It looks like 1.4 is required for this, correct? Any way to do this under 1.3? > On Feb 20, 2022, at 8:17 PM, Mike Bayer wrote: > > the Values construct doesn't have CTE direct support right now so you need to > make a subquery first, then CTE from that > > from sqlalchemy import

Re: [sqlalchemy] Remove/Filter a query.all() results, add a 'virtual' column

2022-02-21 Thread Simon King
Hi, welcome to Python and SQLAlchemy :-) If you want to do some extra filtering on the results, you can iterate over the results, decide whether each item matches your filter conditions, and if it does, append it to a new list, something like this: filtered_results = [] for part in query.all():

Re: [sqlalchemy] CTE w/VALUES in SELECT?

2022-02-20 Thread Mike Bayer
the Values construct doesn't have CTE direct support right now so you need to make a subquery first, then CTE from that from sqlalchemy import Column from sqlalchemy import column from sqlalchemy import Integer from sqlalchemy import select from sqlalchemy import String from sqlalchemy import

[sqlalchemy] Remove/Filter a query.all() results, add a 'virtual' column

2022-02-20 Thread Cp Divers
Hello Guys, this is my very first post here. I'm not sure this the the right place. I'm a week old with Python and SQLAlchemy. And I believe I'm missing a couple concept, hopefully you can help| I do have this class class BLPart(db.Model): __tablename__ = 'BL_parts' ITEMTYPE =

[sqlalchemy] CTE w/VALUES in SELECT?

2022-02-17 Thread Philip Semanchuk
Hi, I'm trying to use a VALUES statement in a CTE, and I can't figure out the correct SQLAlchemy constructs to make this happen. I'd appreciate any help. Here's the SQL I'd like to express in SQLAlchemy -- WITH knights(name, favorite_color) AS ( VALUES ('Lancelot', 'blue'),

Re: [sqlalchemy] garbage collection of instances() generator causing psycopg2.ProgrammingError: named cursor isn't valid anymore

2022-02-16 Thread Mike Bayer
Here's a script that gets as close as possible to what you describe. this uses a psycopg2 server side cursor, queries for 300 rows and fetches in groups of 10 at a time, cutting off the result right at the 15th batch. it doesn't show any problem, but im not sure what else you have going on that

Re: [sqlalchemy] garbage collection of instances() generator causing psycopg2.ProgrammingError: named cursor isn't valid anymore

2022-02-16 Thread Mike Bayer
hi there - this issue does not sound familiar , I guess you are trying to remove the Query iterator before it's exhausted and therefore problems are occurring. I would need to see a stack trace to understand the issue. Also, you shouldn't use Query for cases like these, use modern 1.4 style

[sqlalchemy] garbage collection of instances() generator causing psycopg2.ProgrammingError: named cursor isn't valid anymore

2022-02-16 Thread David Vitek
Hi all, I have a situation where we are using transactions and postgres' server side cursors. The troublesome sequence is something like: x = s.query(...) next(x) if bail_out: s.commit() del x I'm not entirely sure that this simple example can reproduce the problem; the true code is

Re: [sqlalchemy] Self-referential relationship with multiple intermediary tables

2022-02-14 Thread Mike Bayer
I'm not able to reproduce with SQLAlhcemy 1.4. The first join condition given works and if I print a query as follows: s = Session() acc_alias = aliased(Account) print( s.query(Account).join(Account.downstream_accounts.of_type(acc_alias)) ) SQL output is: SELECT account.id AS account_id

[sqlalchemy] Self-referential relationship with multiple intermediary tables

2022-02-12 Thread Dane K Barney
I have a somewhat advanced relationship that I'm trying to define, from a table to itself, but which involves passing through multiple tables to get there. These are my tables: class Account(Base): id = Column(Integer, primary_key=True) class Content(Base): id = Column(Integer,

Re: [sqlalchemy] password rotation after engine created

2022-02-04 Thread Srinu Chp
Thank you Mike for the help. On Friday, February 4, 2022 at 1:49:45 PM UTC-8 Mike Bayer wrote: > you would most easily amend the "costly operation" part of it to cache the > result for a given period of time, so that you can get this password when > you need it from local memory. the

Re: [sqlalchemy] password rotation after engine created

2022-02-04 Thread Mike Bayer
you would most easily amend the "costly operation" part of it to cache the result for a given period of time, so that you can get this password when you need it from local memory. the generated password should be delivered with an approximate expiration time so that you can store it locally

Re: [sqlalchemy] password rotation after engine created

2022-02-04 Thread Srinu Chp
Hello Mike, Thank you very much for prompt response. yes, I tried to update password and every thing works fine but every time I need to fetch new password from secret client is costly operation. So, is there any way I can catch "ORA-01017: invalid username/password; logon denied" and try

Re: [sqlalchemy] password rotation after engine created

2022-02-04 Thread Mike Bayer
we have a recipe for this scheme here: https://docs.sqlalchemy.org/en/14/core/engines.html#generating-dynamic-authentication-tokens no need to connect() inside the event handler, just update the parameters with the new password. On Fri, Feb 4, 2022, at 11:14 AM, Srinu Chp wrote: > Hello

[sqlalchemy] password rotation after engine created

2022-02-04 Thread Srinu Chp
Hello Everyone, We have application, while start up we initialize prepare engine args, configure orm. Once engine created we keep in session. Recently peer team introduced password rotation and for now as work around we are manually restarting the docker container to fetch latest password from

Re: [sqlalchemy] One-to-one relationship not behaving as expected when trying to replace object

2022-02-04 Thread Mike Bayer
yes, do a flush() after removing the old object before applying the new one. On Fri, Feb 4, 2022, at 2:17 AM, Dane K Barney wrote: > Thanks for the explanation, Mike. That makes sense and now I know about this > behaviour. > > > you can get your test program to succeed by sending name=None for

Re: [sqlalchemy] Mapping column names

2022-02-04 Thread Larry Martell
Thanks for the detailed explanation. On Thu, Feb 3, 2022 at 10:18 PM Mike Bayer wrote: > > the names of attributes on your Python class and the names of columns that > are emitted in SQL are two separate things.When you have "jobid = > Column(Integer, ...)" , that's a declarative-only

Re: [sqlalchemy] One-to-one relationship not behaving as expected when trying to replace object

2022-02-03 Thread Dane K Barney
Thanks for the explanation, Mike. That makes sense and now I know about this behaviour. > you can get your test program to succeed by sending name=None for the second B(): I realize my example was pretty trivial, but suppose in a real-world example where table B did not simply have the column

Re: [sqlalchemy] Mapping column names

2022-02-03 Thread Mike Bayer
the names of attributes on your Python class and the names of columns that are emitted in SQL are two separate things.When you have "jobid = Column(Integer, ...)" , that's a declarative-only format that omits the first argument to Column which is the "name"; the declarative mapping process

Re: [sqlalchemy] One-to-one relationship not behaving as expected when trying to replace object

2022-02-03 Thread Mike Bayer
this is the long-expected behavior of the unit of work when issuing a delete() and then an add() of two different objects that nonetheless have the same primary key value - instead of DELETE and INSERT, you get an UPDATE. the reasons have to do with the unit-of-work's ordering of

[sqlalchemy] Mapping column names

2022-02-03 Thread Larry Martell
I normally define a column in a model like this, for example: jobID = Column(Integer, nullable=False, primary_key=True) I now have a case where there are columns in the db that have spaces so I want to map the column name to a variable of a different name. Googling I found this:

[sqlalchemy] One-to-one relationship not behaving as expected when trying to replace object

2022-02-02 Thread Dane K Barney
I have two tables, A and B, that have a one-to-one relationship. Because of this, table B uses the same column as its primary key and the foreign key to table A. For some reason, trying to delete and replace an object of table B is not working as expected. Here is a complete runnable example

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-02-01 Thread Simon
Never mind. This problem is solved by join operations. Thanks for your attention. On Friday, January 28, 2022 at 4:16:05 AM UTC+13 Simon King wrote: > I'm sorry, I still don't understand - what do you expect > query(Genome.attributes) to do? Can you give an example? > > Thanks, > > Simon > > On

Re: [sqlalchemy] Does alembic support multiple databases?

2022-02-01 Thread Ruslan Skira
If you have git example, share, please. On Monday, 30 April 2012 at 04:10:14 UTC+3 limodou wrote: > On Sun, Apr 29, 2012 at 11:13 PM, Michael Bayer > wrote: > > > > On Apr 29, 2012, at 10:56 AM, limodou wrote: > > > >> On Sun, Apr 29, 2012 at 10:42 PM, Michael Bayer > >> wrote: > >>> You would

[sqlalchemy] How to derive table/table name from a column.label()'d object?

2022-01-28 Thread mkmo...@gmail.com
In sqlalchemy Core, I can get the table and table name from a regular column by calling `c.table.name`: from sqlalchemy import table, column t = table('foo', column('bar')) assert hasattr(t.c.bar, 'table') print(t.c.bar.table.name) However, If I label a column, the label no

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-27 Thread Simon King
I'm sorry, I still don't understand - what do you expect query(Genome.attributes) to do? Can you give an example? Thanks, Simon On Wed, Jan 26, 2022 at 11:30 PM Simon wrote: > > Sorry for that the question is not clear. The question is how can we query a > database's property. > > Given the

[sqlalchemy] SQLAlchemy exasol dialect maintainership transfer to Exasol AG

2022-01-27 Thread Peter Hoffmann
Hi all, after years of maintaining the sqlalchemy exasol dialect within Blue Yonder https://github.com/blue-yonder/sqlalchemy_exasol the Exasol AG has stepped up and offered to officially maintain the dialect in the future as part of their open source strategy. We are more than happy about

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-25 Thread jens.t...@gmail.com
Mike, I really appreciate your responses, thank you! All makes sense 邏 Jens On Tuesday, January 25, 2022 at 4:06:03 PM UTC+10 Mike Bayer wrote: > > > On Mon, Jan 24, 2022, at 11:32 PM, jens.t...@gmail.com wrote: > > Mike, thank you for elaborating, that helps a lot! Yes, I meant a transient >

Re: [sqlalchemy] SQL expression object expected, got object of type instead

2022-01-25 Thread Simon King
Can you show the part of *your* code that is triggering the error, and explain what you are trying to do? Plain python properties aren't normally very useful when accessed via a class. "Genome.attributes" returns a property object, not the return value from the function, and I don't understand

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-24 Thread Mike Bayer
On Mon, Jan 24, 2022, at 11:32 PM, jens.t...@gmail.com wrote: > Mike, thank you for elaborating, that helps a lot! Yes, I meant a transient > or pending > > object above, you’re correct. > >

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-24 Thread jens.t...@gmail.com
Mike, thank you for elaborating, that helps a lot! Yes, I meant a transient or pending object above, you’re correct. To make sure I understand correctly: it’s ok to declare deleted_at:

[sqlalchemy] SQL expression object expected, got object of type instead

2022-01-23 Thread Simon
Hi there, I got a problem about 'sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type instead' My SQLAlchemy version is 1.3.22. I have a database like Class Genome: id = Column(Integer, primary_key=True) created_date = Column(Datetime, nullable=False)

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-16 Thread Mike Bayer
On Sat, Jan 15, 2022, at 3:34 PM, jens.t...@gmail.com wrote: > Hello Mike, > > Yes that’s using the plugin: > sqlalchemy[mypy,postgresql_psycopg2binary]==1.4.29 I changed the function > declaration to this: > > @staticmethod > def create(dbsession: Session, name: str, id_:

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-15 Thread jens.t...@gmail.com
Hello Mike, Yes that’s using the plugin: sqlalchemy[mypy,postgresql_psycopg2binary]==1.4.29 I changed the function declaration to this: @staticmethod def create(dbsession: Session, name: str, id_: typing.Union[uuid.UUID, sqlalchemy.dialects.postgresql.base.UUID] = None): and it seems

Re: [sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-13 Thread Mike Bayer
is this with the SQLAlchemy Mypy plugin? current status is for 2.0 we are looking to move away from the plugin model and pretty much change how these things work.Otherwise if this is with the plugin, you would use "id: Mapped[uuid.UUID] = ..." On Wed, Jan 12, 2022, at 9:35 PM,

[sqlalchemy] PostgreSQL UUID type, Python’s UUID — and type hints

2022-01-12 Thread jens.t...@gmail.com
Hello, For a PostgreSQL 14 db, I defined a User mapping and helper function like so: from sqlalchemy.dialects.postgresql import UUID class User(Base): id = Column(UUID(as_uuid=True), primary_key=True, server_default=func.gen_random_uuid()) name = Column(Unicode(128))

Re: [sqlalchemy] Debugging memory leaks

2022-01-12 Thread Mike Bayer
Table objects are normally created at the module level and are persistent for the full lifetime of the application. On Tue, Jan 11, 2022, at 8:03 PM, Anupama Goparaju wrote: > Thanks. > Do you have a minimalistic example on the lifecycle of table objects? Or best > practices of create, use, and

[sqlalchemy] connection in a different thread can't read tables created in another thread?

2022-01-11 Thread niuji...@gmail.com
In a testing suite I have a fixture that drop all the tables in an engine, then start fresh and create all the tables. After this fixture logic, my test case runs, using the newly created table. The fixture and the test case are run in the MainThread, while the database consumer is a web

Re: [sqlalchemy] Debugging memory leaks

2022-01-11 Thread Anupama Goparaju
Thanks. Do you have a minimalistic example on the lifecycle of table objects? Or best practices of create, use, and destroy them? How do we identify if they are continuously created and not destroyed? On Thursday, January 6, 2022 at 5:28:00 AM UTC-8 Mike Bayer wrote: > 1.3.16 doesn't have a lot

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-11 Thread Anupama Goparaju
cx-oracle SessionPool is used underlying that will probe connections on checkout and recover. Hence, trying to disable SQLAlchemy invalidate pool. Thanks! On Monday, January 10, 2022 at 12:04:57 PM UTC-8 Mike Bayer wrote: > > > On Mon, Jan 10, 2022, at 1:30 PM, Anupama Goparaju wrote: > >

[sqlalchemy] Re: [Proposal] Some simple high-level feature to set connection timeouts

2022-01-10 Thread Don Nillo
Yup. Sure. I meant "query timeouts", not "connection timeouts". May be a good option could be like this: connection.execute(stmt, timeout=MAX_TIME) Anyway, thanks. (Admins, please, feel free to delete this conversation. I'm ashamed for not using search properly. Sorry for that) On Monday,

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-10 Thread Mike Bayer
On Mon, Jan 10, 2022, at 1:30 PM, Anupama Goparaju wrote: > Thanks. Looks like this works but we need to set it for every exception > scenario. Just confirming if the exception_context is thread safe to set the > attribute. yes this all happens local to the execute() function call, is not

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-10 Thread Anupama Goparaju
Thanks. Looks like this works but we need to set it for every exception scenario. Just confirming if the exception_context is thread safe to set the attribute. Also, does this setting prevent pool invalidation on all sort of exceptions related to connections? @event.listens_for(Engine,

[sqlalchemy] Re: [Proposal] Some simple high-level feature to set connection timeouts

2022-01-10 Thread Jonathan Vanasco
SQLAlchemy supports connection timeouts to establish a connection already. SQLAlchemy does not, and can not, support query timeouts. This is possible with some python database drivers, but very rare. In every Python database program/library query timeouts are typically handled on the database

[sqlalchemy] RE: builtins.NoneType' is not mapped

2022-01-10 Thread Clive Swan
Greetings, I am getting the following error, any suggestions would be welcomed. When running: deleteVersionStamp self.session.delete(rec) File “\Externals\win32\Lib\site-packages\sqlalchemy\orm\scoping.py”, line 162, in do return getattr(self.registry(), name)(*args, **kwargs)

[sqlalchemy] Re: [Proposal] Some simple high-level feature to set connection timeouts

2022-01-10 Thread Don Nillo
UPD: found out cx_Oracle also has Connection.cancel() method. May be things are not that bad On Monday, January 10, 2022 at 12:52:49 PM UTC+3 Don Nillo wrote: > Hi! > Sorry for bothering, I have not enough skills to contribute yet ( > But... > I think it would be great to have some feature to

[sqlalchemy] Re: Create association of three or more tables

2022-01-10 Thread fco...@gmail.com
Hi, A colleague helped me to write the relationship() part, the working code with relationships is now : class UserOrgRole(Base): __tablename__ = "user_org_role" user_id = Column(ForeignKey("user.id", ondelete="CASCADE"), primary_key=True ) org_id = Column(ForeignKey("org.id",

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-07 Thread nicolas...@jobteaser.com
Don't get me wrong, I only have praises for the work currently being done on removing all the `bind`. It was one of the things that had me confused with SQLAlchemy when I started working with it some years back and also caused me a few headaches. And honestly after weighing the pros and cons,

Re: [sqlalchemy] With loader criteria and baked query cache

2022-01-07 Thread Mike Bayer
i dont think with_loader_criteria ever expected the target entity to be part of "secondary" in a relationship(). I have no idea what that would do and I'm surprised it works at all. I would try instead to map from A->A_rel_B->B explicitly and use two relationships for this join. On Fri,

[sqlalchemy] With loader criteria and baked query cache

2022-01-07 Thread Tomas Pavlovsky
Hello Mike, class X() id: id: int = Column( Integer, primary_key=True) a_id:int = Column(Integer, ForeignKey("A.id")) subq = select(A_rel_B).join(B).order(B.size).limit(10) class A() id: id: int = Column( Integer, primary_key=True) bs = relationship(B, viewonly=True,

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-07 Thread Jonathan Vanasco
> Ok. So if I understand you correctly, you want to keep query parameters solely for DBAPI drivers connection parameters and would hence not accept a PR that would implement something that changes that. Just adding: the standard across programming languages and database products/projects is to

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-07 Thread Mike Bayer
also if you really want your app to have just one URL with all kinds of config in it, then just use that. get the URL object using the make_url() API, pull out the configuration you need from URL.query, make a new URL from that one that is for your database, then connect.it's all public

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-07 Thread Mike Bayer
the idea of Table objects being linked to a database is something I thought was a good idea in 2006, which is why for the last 15 years there's been this notion of "bound metadata" that associates a specific engine with Table objects. however, probably by 2009 if not earlier, the limited and

[sqlalchemy] Create association of three or more tables

2022-01-07 Thread fco...@gmail.com
Hi all, I would like to create some association of, at least, 3 tables User, Org (organisation) and Role : a User is given a Role on an Organisation. So I began writing the following snippet but I am stucked as I do not know how I should write relationship() for User to be able to refer Orgs

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-07 Thread nicolas...@jobteaser.com
Hi ! Ok. So if I understand you correctly, you want to keep query parameters solely for DBAPI drivers connection parameters and would hence not accept a PR that would implement something that changes that. There are other reasons though for which I was looking into this. In particular, what I

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-06 Thread Anupama Goparaju
Thanks, i will give it a try. On Thursday, January 6, 2022 at 5:23:09 AM UTC-8 Mike Bayer wrote: > I can't guarantee that overriding private methods is safe, no. > > there's a public API to disable errors resulting in invalidation, I > suggest you use that. > > > > On Wed, Jan 5, 2022, at 7:35

Re: [sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-06 Thread Mike Bayer
hey there - database URLs do support query string parameters, however they have a specific meaning which is that they are consumed by the DBAPI in use, not the dialect directly. Please review the docs at

[sqlalchemy] [Question] Why not passing Connection URL query parameters to the dialect?

2022-01-06 Thread nicolas...@jobteaser.com
Hi ! While working on some improvements to PyAthena, I was looking into means to pass some parameters to the dialect. Going through the code of the ` create_engine()` function code, I saw that dialects `__init__()` where given dialect kwargs passed as kwargs

Re: [sqlalchemy] Debugging memory leaks

2022-01-06 Thread Mike Bayer
1.3.16 doesn't have a lot of caching going on compared to the 1.4 series. it's expected that memory in an ORM application will grow for a few iterations as there is some caching of things, but a "leak" is defined as growth that never stops. you'd want to verify that the growth you see does

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-06 Thread Mike Bayer
I can't guarantee that overriding private methods is safe, no. there's a public API to disable errors resulting in invalidation, I suggest you use that. On Wed, Jan 5, 2022, at 7:35 PM, Anupama Goparaju wrote: > I haven't read the response before and tried to skip the lib logic by >

[sqlalchemy] Debugging memory leaks

2022-01-05 Thread Anupama Goparaju
Hi, We are trying to debug memory leaks in our flask app that is using SQLAlchemy version 1.3.16. When i was using tracemalloc python library and comparing the memory snapshots, I found the below lines repetitively appearing in the snapshot differences: Could you please help us in providing us

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-05 Thread Anupama Goparaju
I haven't read the response before and tried to skip the lib logic by overriding the function below in my child call extending the NullPool to do nothing. Is this safe to do? def _invalidate(self, connection, exception=None, _checkin=True): pass On Wednesday, January 5, 2022 at 4:33:01

Re: [sqlalchemy] Turn off connections invalidation functionality

2022-01-05 Thread Anupama Goparaju
Great, thanks for the info. On Friday, November 26, 2021 at 9:30:02 AM UTC-8 Mike Bayer wrote: > I've spent some time thinking about what might be being asked here.the > only thing I can think of is that when a particular database connection is > found to be in what we call a "disconnect"

Re: [sqlalchemy] Best practices for sub-dividing a large collection relationship

2021-12-31 Thread Mike Bayer
if you need an in-memory dictionary of all the edges at once, then where is the part that you dont want the whole thing loaded at once? or is the idea that this dictionary is checking for uniqueness within the scope of what's being added in the current session (I'd use a separate dictionary

Re: [sqlalchemy] Best practices for sub-dividing a large collection relationship

2021-12-30 Thread Dane K Barney
Hey Mike, thanks for your speedy reply. I guess I left out some key details and simplified my examples a little too much, which is probably why you're confused. For one, I have actually implemented downstream_edges and upstream_edges as dictionary collections, i.e.: src_node = relationship(

Re: [sqlalchemy] Best practices for sub-dividing a large collection relationship

2021-12-30 Thread Mike Bayer
On Thu, Dec 30, 2021, at 8:10 PM, Dane K Barney wrote: > Given the following example model: > > class Node(Base): > __tablename__ = "node" > id = Column(Integer, primary_key=True, autoincrement=True) > > class Edge(Base): > __tablename__ = "edge" > id = Column(Integer,

[sqlalchemy] Best practices for sub-dividing a large collection relationship

2021-12-30 Thread Dane K Barney
Given the following example model: class Node(Base): __tablename__ = "node" id = Column(Integer, primary_key=True, autoincrement=True) class Edge(Base): __tablename__ = "edge" id = Column(Integer, primary_key=True, autoincrement=True) color = Column(Enum(Color))

[sqlalchemy] Re: SQLAlchemy with postgres: crash sqlalchemy connection with thread parallelism,

2021-12-20 Thread Jonathan Vanasco
Please submit a "Short, Self Contained, Correct (Compilable), Example" along with any potential bug reports. http://sscce.org/ On Wednesday, December 15, 2021 at 11:29:30 AM UTC-5 Ramin Farajpour Cami wrote: > Hi, > > I'm was testing the project by fastapi + sqlalchemy, i write golang code >

[sqlalchemy] Current experiences with async Python and dbs?

2021-12-19 Thread jens.t...@gmail.com
Hello, We’ve been debating the performance of “standard” Python vs. async Python lately, in the context of db-backed web services. For web services, the blog Async Python is not faster

[sqlalchemy] SQLAlchemy with postgres: crash sqlalchemy connection with thread parallelism,

2021-12-15 Thread Ramin Farajpour Cami
Hi, I'm was testing the project by fastapi + sqlalchemy, i write golang code for sending thread parallelism to the my API endpoint, I found a problem, in the sqlalchemy many requests fail, this is my config : SQLALCHEMY_DATABASE_URL = config("DATABASE_URL") engine =

Re: [sqlalchemy] Setting up indexes in __table_args__ that depend on columns created in __declare_first__

2021-12-14 Thread Mike Bayer
Hi Randy! inside of __declare_first__() the table is ready, you can just set it up def __declare_first__(cls): Index("my_idx", cls.__table__.c.colname) have a great holiday season! - mike On Tue, Dec 14, 2021, at 4:32 PM, 'Randy Syring' via sqlalchemy wrote: > I'm trying to create a

[sqlalchemy] Setting up indexes in __table_args__ that depend on columns created in __declare_first__

2021-12-14 Thread 'Randy Syring' via sqlalchemy
I'm trying to create a mixin that will setup FK columns that are dynamically named based on the name of the parent as opposed to a static name like `parent_id`. If was going to do the latter, I could easily use `declarted_attr` but since I want the former, I thought I could use

Re: [sqlalchemy] How to SELECT computed data using SQLAlchemy?

2021-12-14 Thread 'Daniel Grindrod' via sqlalchemy
That worked brilliantly, thanks so much for your help! Very much appreciated :) On Tuesday, 14 December 2021 at 18:16:02 UTC Mike Bayer wrote: > > > On Tue, Dec 14, 2021, at 12:26 PM, 'Daniel Grindrod' via sqlalchemy wrote: > > Hi Michael, > > Thanks for such a quick reply. > I enjoyed reading

Re: [sqlalchemy] How to SELECT computed data using SQLAlchemy?

2021-12-14 Thread Mike Bayer
On Tue, Dec 14, 2021, at 12:26 PM, 'Daniel Grindrod' via sqlalchemy wrote: > Hi Michael, > > Thanks for such a quick reply. > I enjoyed reading it! I actually inherited this API (I swear I'm not just > making excuses!) from a colleague who left a few months earlier, so it's very > much been a

Re: [sqlalchemy] How to SELECT computed data using SQLAlchemy?

2021-12-14 Thread 'Daniel Grindrod' via sqlalchemy
Hi Michael, Thanks for such a quick reply. I enjoyed reading it! I actually inherited this API (I swear I'm not just making excuses!) from a colleague who left a few months earlier, so it's very much been a case of 'Figuring it out as I go along'. Apologies for the incomplete code - despite it

Re: [sqlalchemy] How to SELECT computed data using SQLAlchemy?

2021-12-14 Thread Mike Bayer
On Tue, Dec 14, 2021, at 5:40 AM, 'Daniel Grindrod' via sqlalchemy wrote: > Hi all, > > I'm working on a REST API which is built using Flask-SQLAlchemy and > Connexion. I'm fairly new to SQLAlchemy, but it's been brilliant so far :) > This API uses SQLAlchemy 1.3.16, and connects to an Oracle

[sqlalchemy] How to SELECT computed data using SQLAlchemy?

2021-12-14 Thread 'Daniel Grindrod' via sqlalchemy
Hi all, I'm working on a REST API which is built using Flask-SQLAlchemy and Connexion. I'm fairly new to SQLAlchemy, but it's been brilliant so far :) This API uses SQLAlchemy 1.3.16, and connects to an Oracle Database (12c 12.1.0.1.0 64bit).

Re: [sqlalchemy] Not able to importing fixtures from sqlalchemy from 1.3.16 version

2021-12-12 Thread Mike Bayer
On Sat, Dec 11, 2021, at 12:36 PM, sairohith yerramilli wrote: > > Hi, > Thank you for response. > I would like to inform you that , for testing that code I am using pytest > only. What i am facing is, it is worked properly till Sqlalchemy version > 1.3.15. When I upgraded the Sqlalchemy

Re: [sqlalchemy] Not able to importing fixtures from sqlalchemy from 1.3.16 version

2021-12-11 Thread sairohith yerramilli
Hi, Thank you for response. I would like to inform you that , for testing that code I am using pytest only. What i am facing is, it is worked properly till Sqlalchemy version 1.3.15. When I upgraded the Sqlalchemy version to 1.3.17 ,mentioned piece of code is failing at import level

<    3   4   5   6   7   8   9   10   11   12   >