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

2023-05-13 Thread Shane Holcombe
I've tested both solutions, the first one, moving the if c is None: return down a few lines seems to work and the generated SQL still seems to be correct in the instances where that code is triggered. >From some early testing as well the other solution seems to work as well, it's hard to test

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

2023-05-12 Thread Mike Bayer
in the below mentioned issue I've created a patch at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/4615 that removes a thread-sensitive approach to generating an internal structure, which is where I suspect this might be happening (if anywhere), and then it also adds a guard against

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

2023-05-12 Thread Mike Bayer
I've opened https://github.com/sqlalchemy/sqlalchemy/issues/9777 for this. I have another theory where something might be going wrong earler in the chain. This change would be "simpler" in that it removes something that's complicated, prone to race conditions hence seems a good possibility

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

2023-05-12 Thread Shane Holcombe
There seems to be a few moving parts to this so it's been hard to track down, I can give that fix a try in a few hours when I'm home. I was worried something like that might lose some columns but I'll try and see what happens. Thanks On Saturday, May 13, 2023 at 12:59:33 PM UTC+10 Mike Bayer

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

2023-05-12 Thread Mike Bayer
well, not sure yet how a None is coming in there that is sporadic, or even at all, but if that's what's happening then we would think this patch would fix the problem, the Q is does the query still produce the correct results: diff --git a/lib/sqlalchemy/orm/strategies.py

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

2023-05-12 Thread Mike Bayer
OK, maybe you are onto something with the theory re: JoinedLoader._generate_row_adapter(). will look at that On Fri, May 12, 2023, at 6:16 PM, Shane Holcombe wrote: > Thanks for linking that github issue, completely missed that one. > > Here's the complete stack trace, sorry for not including

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

2023-05-12 Thread Shane Holcombe
Thanks for linking that github issue, completely missed that one. Here's the complete stack trace, sorry for not including that at the start Traceback (most recent call last): File "/Users/sfh/env/vita/lib/python3.9/site-packages/werkzeug/serving.py", line 333, in run_wsgi

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-12 Thread S Mahabl
https://stackoverflow.com/questions/48811239/how-to-set-alias-in-the-sqlalchemy-for-the-table Another idea is to create a view in another schema pointing to the same table ... On Fri, May 12, 2023 at 3:48 PM Benjamin Taub wrote: > Thanks for the suggestion. > I thought about using an alias but

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

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

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-12 Thread Benjamin Taub
Thanks for the suggestion. I thought about using an alias but came up with two problems: 1) The FROM clause is auto-generated from SELECT clause, so I'm not sure where I would add this alias 2) All the aliases in the SELECT clause are also double-quoted. I believe a single backquote would be

Re: [sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-12 Thread S Mahabl
Is there alias you can give for *283ac7717fe770c5ed6d425c0c739cba".t_59a33cbea3617986d810e9fbae60ba19 XYZ* *?* On Fri, May 12, 2023, 3:30 PM Benjamin Taub wrote: > I have code that worked under SQLAlchemy 1.4 but recently upgraded to 2. I > am using the add_columns() method to add columns to

[sqlalchemy] Inconsistent SQL Generation in 2.0

2023-05-12 Thread Benjamin Taub
I have code that worked under SQLAlchemy 1.4 but recently upgraded to 2. I am using the add_columns() method to add columns to an existing SQL statement. The resultant queries sometimes, but not always, crash. I believe the issue happens when the schema/database name (I'm using MySQL) starts

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

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

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

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

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

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

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

2023-05-11 Thread Shane Holcombe
Hi there, I've been working on migrating our codebase from SQLAlchemy 1.4 to 2.0 and have encountered an issue I can't seem to get around. The error itself is File "/Users/sfh/env/vita/lib/python3.9/site-packages/sqlalchemy/orm/context.py", line 1101, in create_for_statement

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

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

[sqlalchemy] Transaction integrity issue in SQLAlchemy SQLite dialect

2023-05-10 Thread Roman Diba
Summary: The SQLAlchemy SQLite dialect does not fully support serializable transaction isolation in SQLite, leading to potential invalid data when transactions interleave. Hello, This report documents an issue with transaction integrity in the SQLAlchemy SQLite dialect. SQLite itself is

Re: [sqlalchemy] How to set Row instance attribute

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

[sqlalchemy] How to set Row instance attribute

2023-05-06 Thread sector119
Hello, I get some data from DB and have a sequence of Row objects, how it is possible to modify data in those objects attrs? Something like result = await dbsession.execute(query) services = result.all() for i, service in enumerate(services): services[i].title = f"some text here

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

2023-05-03 Thread 'Tony Cosentini' via sqlalchemy
Just to follow up on what I ended up doing - I went with approach 1 and created a function that would add it. I also switched from __ to _ to avoid any surprises. Thanks again for the suggestions! On Wednesday, May 3, 2023 at 9:27:57 PM UTC+8 Mike Bayer wrote: > I'd be a little concerned

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

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

[sqlalchemy] DRYing up model relationships with custom properties

2023-05-03 Thread 'Tony Cosentini' via sqlalchemy
Hi, I have a pattern in some models where there is a private (as in prefixed with __) relationship and then a property to handle some things that need to happen when the relationship is fetched or written to. Currently it's implemented like this: class ModelClass(Base):

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

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

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

2023-04-30 Thread Erabil Erabil
Wouldn't the 'with' block already automatically close the session if I'm already using it to establish the session? 29 Nisan 2023 Cumartesi tarihinde saat 05:50:10 UTC+3 itibarıyla Nishant Varma şunları yazdı: > See if this helps: > > >

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

2023-04-28 Thread Nishant Varma
See if this helps: https://docs.sqlalchemy.org/en/20/orm/session_basics.html#session-faq-whentocreate and https://docs.sqlalchemy.org/en/20/orm/contextual.html Session should be closed correctly etc. On Fri, Apr 28, 2023, 10:18 PM Erabil Erabil wrote: > When using SQL Alchemy in a Flask

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

2023-04-28 Thread Erabil Erabil
When using SQL Alchemy in a Flask application, if the application continuously sends queries to the database, it exceeds the maximum number of connections in the connection pool. How can I solve this issue? *sqlalchemy_engine.py* import os from sqlalchemy import create_engine from

Re: [sqlalchemy] StaleDataError on simple update statement

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

[sqlalchemy] StaleDataError on simple update statement

2023-04-26 Thread Mirel Glejser
I am completely stumped after working on this issue for 2 days. I am simply querying a user, updating the name, and sending it back to the database. user = session.query(User).get(1) user.first_name # John user.first_name = 'Sally' session.commit() # > sqlalchemy.orm.exc.StaleDataError:

Re: [sqlalchemy] Change a select clause + add a join automatically

2023-04-20 Thread Nishant Varma
Thank you! It is indeed a query-interception requirement, so that looks appropriate. I will have a deeper look on how it can be used. Rgds On Thu, Apr 20, 2023, 3:08 PM Simon King wrote: > I think this is the intended use for the do_orm_execute event and the > with_loader_criteria query

Re: [sqlalchemy] Change a select clause + add a join automatically

2023-04-20 Thread Simon King
I think this is the intended use for the do_orm_execute event and the with_loader_criteria query option: https://docs.sqlalchemy.org/en/14/orm/session_events.html#do-orm-execute-global-criteria https://docs.sqlalchemy.org/en/14/orm/query.html#sqlalchemy.orm.with_loader_criteria You ought to be

Re: [sqlalchemy] Re: Dealing with readonly column

2023-04-18 Thread Jonathan Vanasco
FWIW, I often use the events to ensure an object or column is "read only". Sometimes I also will use two different attributes, where `Object.foo` is a getter for `Object._foo` in the database. The database will raise an error (hopefully) if I try to write to a 'protected column', and

Re: [sqlalchemy] Modifying Query Object

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

Re: [sqlalchemy] Modifying Query Object

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

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that we

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to pass

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance "(server.db.models.Data object at , '2021-04-10 18', Decimal('7294.0'))".", Here I am able to get the max for that

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Peter Harrison
I have some additional context on the issue Luis mentioned. 1. We are using the graphene-sqlalchemy package. 2. When you do a GraphQL web api query, the package creates a sqlalchemy.orm.query.Query object. 3. We want to modify this standard query that the package creates so that we

Re: [sqlalchemy] Modifying Query Object

2023-04-14 Thread Luis Del Rio IV
The sql query itself returns several rows, as it should. But when trying to combine the max using sqlalchemy the rows return as the following. Received incompatible instance \"(, '2021-04-10 18', Decimal('7294.0'))\".", Here I am able to get the max for that row group, but am unable to

Re: [sqlalchemy] Re: Dealing with readonly column

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

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

2023-04-14 Thread Mike Bayer
this line of code: query = session.query(CodigoProduto.CdChamada, Produto.IdProduto, Produto.NmProduto, ProdutoEmpresa.VlPrecoCusto, ProdutoEmpresa.VlPrecoSugerido, EstoqueEmpresa.DtReferencia, EstoqueEmpresa.QtEstoque) should look like this: query =

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

2023-04-14 Thread Elias Coutinho
*I am suffering!It showed the same message.* # Subquery para buscar o maior registro de estoqueempresa para cada produto estoqueAtual = session.query( EstoqueEmpresa.IdProduto, EstoqueEmpresa.QtEstoque, func.max(EstoqueEmpresa.DtReferencia).label('MaxDtReferencia')

[sqlalchemy] Re: Dealing with readonly column

2023-04-14 Thread Lele Gaifax
"Mike Bayer" writes: > On Fri, Apr 14, 2023, at 8:03 AM, Lele Gaifax wrote: >> I now have >> >> CREATE TABLE something (id SERIAL, name TEXT) >> >> CREATE FUNCTION counter(something) >> RETURNS INTEGER AS $$ >> SELECT count(*) FROM something_else se >> WHERE se.something_id = $1.id

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

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

[sqlalchemy] Using joins+max with sql server

2023-04-14 Thread Elias Coutinho
Good afternoon. I am having trouble transforming a SQL Server query to SQL Alchemy. *The SQL Server query is this* SELECT CP.CdChamada, P.NmProduto, PE.VlPrecoCusto, PE.VlPrecoSugerido, EE.QtEstoque, EE.DtReferencia FROM Produto P INNER JOIN Produto_Empresa PE ON P.IdProduto = PE.IdProduto

Re: [sqlalchemy] Dealing with readonly column

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

[sqlalchemy] Dealing with readonly column

2023-04-14 Thread Lele Gaifax
Hi, I wonder if there is a way to declare a particular column of a table as "readonly", either for the purpose of documenting the model, or to get early error should someone try to update it. Some context: I have to maintain an old application, based on PostgreSQL, with several surrounding tools

Re: [sqlalchemy] Query object modification

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

Re: [sqlalchemy] Query object modification

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

Re: [sqlalchemy] Query object modification

2023-04-13 Thread Luis Del Rio IV
Mike, Would this select query be able to get our aggregated data? query = select(func.max(DataModel.value)).select_from(_query .subquery()).group_by( func.date_format(DataModel.timestamp, "%Y-%m-%d %H") ) We tried this route but are now getting this error

Re: [sqlalchemy] Query object modification

2023-04-13 Thread Peter Harrison
Thanks Mike, Ideally we'd prefer to find a solution via Graphene-SQLAlchemy. Unfortunately we don't have the luxury of creating our own query when interacting with Graphene-SQLAlchemy. So the key question for us is, can you modify an existing sqlalchemy.orm.query.Query object to insert a

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

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

[sqlalchemy] Access other columns in a custom type

2023-04-13 Thread Hussein Samadi
Hi everyone. I'm creating a new SQLA custom type using TypeDecorator base class. Is it possible to have access to the value of other fields in "process_result_value" method? Generally, is it possible to create a custom type that have access to other column's data in the de-serialization

Re: [sqlalchemy] Query object modification

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

[sqlalchemy] Query object modification

2023-04-12 Thread Luis Del Rio IV
I am currently using the following sqlalchemy code, _query = super().get_query(model, info, sort, **args) query = _query.group_by( func.date_format(DataModel.timestamp, "%Y-%m-%d %H") ) return query I am trying to aggregate the the max value of a

[sqlalchemy] Re: trying to create a custome dialect did not find proper step guide

2023-04-12 Thread Jonathan Vanasco
There are no guides, because this is a very advanced topic. If you are unable to code this based on the examples I shared above, you will have to find someone who can. On Friday, April 7, 2023 at 11:41:30 PM UTC-4 sayakchak...@gmail.com wrote: > Thank you sir for your response ,can you

Re: [sqlalchemy] chinook with sqlalchemy core

2023-04-12 Thread Soumaya Mauthoor
Or any sample database would e.g. northwind https://docs.devexpress.com/XtraReports/403995/product-information/sample-northwind-database Le mer. 12 avr. 2023 à 20:40, sumau a écrit : > Hello > > Is there a sqlalchemy core version of the chinook database >

[sqlalchemy] chinook with sqlalchemy core

2023-04-12 Thread sumau
Hello Is there a sqlalchemy core version of the chinook database https://github.com/lerocha/chinook-database? A python script which creates the different tables and populates them with the same data? Regards Soumaya -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

Re: [sqlalchemy] Modifying Query Object

2023-04-11 Thread S Mahabl
Do you get many rows? SELECT date_format(data.timestamp, "%Y-%m-%d %H"), max(data.value) AS data_value from data GROUP BY date_format(data.timestamp, "%Y-%m-%d %H") On Tue, Apr 11, 2023 at 4:24 PM Luis Del Rio IV wrote: > Hello, > > I am currently using the following sqlalchemy code, > >

[sqlalchemy] Modifying Query Object

2023-04-11 Thread Luis Del Rio IV
Hello, I am currently using the following sqlalchemy code, _query = super().get_query(model, info, sort, **args) query = _query.group_by( func.date_format(DataModel.timestamp, "%Y-%m-%d %H") ) return query I am trying to aggregate the the max value of

[sqlalchemy] Change a select clause + add a join automatically

2023-04-11 Thread Nishant Varma
Hello, I have this schema: class Question(Base): __tablename__ = "question" idn = Column(Integer, primary_key=True) text = Column("text", String) translations = relationship("Translation", backref="question") class Translation(Base): __tablename__ = "translation" idn =

[sqlalchemy] Re: trying to create a custome dialect did not find proper step guide

2023-04-07 Thread sayak chakraborty
Thank you sir for your response ,can you please guide me about how to create a customs dialect because in sqlalchemy i find a topic on 3rd party dialect but i dont fine and proper guide for it if you can please can you provide me guide. On Friday, April 7, 2023 at 11:12:14 PM UTC+5:30

Re: [sqlalchemy] missing schema authorization clause

2023-04-07 Thread sumau
Thanks Mike that works perfectly. Regards Soumaya On Wednesday, 5 April 2023 at 23:44:35 UTC+1 Mike Bayer wrote: > I've never heard of this concept before so a google into stack overflow > shows > https://stackoverflow.com/questions/10994414/missing-authorization-clause-while-creating-schema,

[sqlalchemy] Re: trying to create a custome dialect did not find proper step guide

2023-04-07 Thread Jonathan Vanasco
Most custom dialects are written by forking an existing dialect. Unfortunately, a dialect can not accomplish what you want to do. SqlAlchemy Dialects are used to generate SQL, which is then passed to the database via a DBAPI driver. For example, when someone uses PostgreSQL with SQLAlchemy,

[sqlalchemy] trying to create a custome dialect did not find proper step guide

2023-04-06 Thread sayak chakraborty
create a custom SQLAlchemy dialect, called PCRRESTapiDialect for SQL Alchemy that can call a rest api and return result as a table. i am trying to achive this but i dont find any solution -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

Re: [sqlalchemy] missing schema authorization clause

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

[sqlalchemy] missing schema authorization clause

2023-04-05 Thread sumau
Hello Is it possible to pass in the authorization when creating a schema with the oracle dialect? oracle_engine = create_engine( f"oracle://{user}:{password}@{host}:{port}/{database_name}" ) inspector = inspect(oracle_engine) if schema_name not in inspector.get_schema_names():

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Jonathan Vanasco
> The only difference between my code and yours is that I am not using sessions. The Flask-Sqlalchemy package handles all the session stuff automatically in the background. The code you write is not interacting with the session explicitly, but it is utilizing the session implicitly. IMHO,

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Nancy Andeyo
The solution that finally worked for me is: *from sqlalchemy import extract #monthly_events = current_user.followed_events().filter(Event.event_date < datetime.today().date()).filter(extract('month', Event.event_date) ==

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Nancy Andeyo
The only difference between my code and yours is that I am not using sessions. Might it be the reason why my query is not working as expected? Here is my query one more time: monthly_events = current_user.followed_events().filter(Event.event_date <

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Nancy Andeyo
The only difference between my code in is that I am not using session. Might it be the reason why my query is not working as expected? Here is my query one more time: monthly_events = current_user.followed_events().filter(Event.event_date < datetime.today().date()).filter(func.strftime('%m',

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread James Paul Chibole
Sorry, it is a type, it should actually be .filter(func.strftime('%m', Event.event_date == datetime.today().strftime('%m'))) Let me go through your latest response and will get back to you. Thank you for the prompt response. On Wed, Apr 5, 2023 at 10:16 AM Lele Gaifax wrote: > Nancy Andeyo

[sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Lele Gaifax
Nancy Andeyo writes: > However, the part with problems is this one: .filter(func.strftime('%m', > Event.event_date = datetime.today().strftime('%m'))) where the aim to > filter out events that will take place in the current month. This is the > section that I posted, yet I needed to post the

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Nancy Andeyo
Hi Lee, thanks for responding. The code was only part of the entire query, perhaps I needed to provide the entire query and try to explain and give an explanation a little bit. Here is the entire code: monthly_events = current_user.followed_events().filter(Event.event_date <

Re: [sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Nancy Andeyo
Hi Lee, thanks for responding. The code was only part of the entire query, perhaps I needed to provide the entire query and try to explain and give an explanation a little bit. Here is the entire code: monthly_events = current_user.followed_events().filter(Event.event_date <

[sqlalchemy] Re: Working with func in dates, No response, no error message

2023-04-05 Thread Lele Gaifax
Nancy Andeyo writes: > the filter *.filter(func.strftime('%m', func.date(Events.date_of_event) == > datetime.today().strftime('%m')))* to get all the events that happened in > the current month is not working. But displays all the events. Read carefully what you have written: >

Re: [sqlalchemy] Working with func in dates, No response, no error message

2023-04-04 Thread Nancy Andeyo
I am still struggling to find the solution on this issue, the issue is with the func, because when I omit the comparison with the the func sqlachemy function, the outcome is expected. However, I want to ensure that only items for this month are displayed: he filter *.filter(func.strftime('%m',

Re: [sqlalchemy] Working with func in dates, No response, no error message

2023-04-04 Thread Nancy Andeyo
I am still struggling to find the solution on this issue, the issue is with the func, because when I omit the comparison with the func sqlalchemy function, the outcome is expected. However, I want to ensure that only items for this month are displayed: he filter *.filter(func.strftime('%m',

Re: [sqlalchemy] relationships between inheritance tables

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

Re: [sqlalchemy] Working with func in dates, No response, no error message

2023-03-30 Thread James Paul Chibole
Thank you Philip for your suggestion. On Thursday, March 30, 2023 at 9:38:08 PM UTC+3 Philip Semanchuk wrote: > > > > On Mar 30, 2023, at 2:32 PM, James Paul Chibole > wrote: > > > > Hi everyone, I am trying to retrieve deceased persons who died in the > current month but the output gives no

Re: [sqlalchemy] Working with func in dates, No response, no error message

2023-03-30 Thread Philip Semanchuk
> On Mar 30, 2023, at 2:32 PM, James Paul Chibole wrote: > > Hi everyone, I am trying to retrieve deceased persons who died in the current > month but the output gives no result. Here is my code with query done in > Python Flask: > from datetime import datetime

[sqlalchemy] Working with func in dates, No response, no error message

2023-03-30 Thread James Paul Chibole
Hi everyone, I am trying to retrieve deceased persons who died in the current month but the output gives no result. Here is my code with query done in Python Flask: from datetime import datetime from sqlalchemy import func

[sqlalchemy] relationships between inheritance tables

2023-03-29 Thread Kaan Baha Sever
Hello! I have three post type and inherit from post table. And this post have comment and like table foreign key. But I am using this method my performance very very low. One page loading 3-4 sec. How can I do? My Tables Post(Model): id name PostType1(Post): id content PostType2(Post): id body

Re: [sqlalchemy] TLS 1.2

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

[sqlalchemy] Re: TLS 1.2

2023-03-28 Thread Jonathan Vanasco
Many users with similar experiences ultimately traced the issue to an outdated database driver. I would try updating your driver. If that does not work, please share the driver + version, and your connection string / code. On Monday, March 27, 2023 at 2:39:21 PM UTC-4 pdb...@g.clemson.edu

[sqlalchemy] TLS 1.2

2023-03-27 Thread Patrick Bruce
I am connecting to a MySQL db using sqlalchemy and TLS 1.2 is enforced server side. I connect by setting my URI to the correct connection string and adding the ?ssl=true flag at the end. However I am getting an error that the TLS version does not meet the minimum requirements of the server. My

[sqlalchemy] Re: How to use sqlcodegen generate SQLModels

2023-03-22 Thread Val Huber
You might want to consider API Logic Server . It includes sqlacodegen, and uses it to build an executable project including an API and an Admin App. On Wednesday, March 22, 2023 at 3:55:20 PM UTC-7 Linson Abah wrote: > Hi, > I am trying to convert the

Re: [sqlalchemy] How to use sqlcodegen generate SQLModels

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

[sqlalchemy] How to use sqlcodegen generate SQLModels

2023-03-22 Thread Linson Abah
Hi, I am trying to convert the schema of a db to SQLModels: I have this short script: *from subprocess import calloutfile = 'models/dvdrental_models.py'generator = 'sqlmodels'call(['sqlacodegen', db_uri, '--generator', generator, '--outfile', outfile])* I got this Error. sqlacodegen:

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

2023-03-21 Thread Mike Bayer
MySQL's "only full group by" option causes MySQL to use the SQL standard for GROUP BY, which states that all columns that are not contained within an aggregate function must be in the GROUP BY clause. That is, this SQL is invalid: SELECT table.x, max(table.y) FROM table The reason is that

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

2023-03-21 Thread 'Dan Stromberg [External]' via sqlalchemy
Granted, it’s difficult to read my (admittedly rather blank) mind. Maybe I should restate the question: What are my options? I just want to see the rows from the query below. Why is it telling me I need to aggregate, and if I do truly need to, what might be an aggregate function that won’t

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

2023-03-21 Thread Mike Bayer
ill clarify that para in the reflection part On Tue, Mar 21, 2023, at 11:15 AM, Pierre Massé wrote: > Thanks for this quick answer Mike! > > Obivously, I wasted way to much energy in trying to make everything work with > table reflection... :( Let's say I gained experience from it. > >

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

2023-03-21 Thread 'Dan Stromberg [External]' via sqlalchemy
Hoping to save an iteration: the SQL currently looks like: [SQL: SELECT tb_nv.id, min(bs_3.build_id) AS min_1 FROM tb_nv, tb_brst AS bs_3, tb_brst AS bs INNER JOIN tb_vers AS v_2 ON bs.version_id = v_2.id, tb_brst AS bs_2 INNER JOIN tb_br ON tb_br.id = bs_2.branch_id] From: 'Dan Stromberg

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

2023-03-21 Thread 'Dan Stromberg [External]' via sqlalchemy
Alright, using join_from may have led to clearing a hurdle. I’m now using: query = ( select(NV.id, func.min(bs_3.build_id)) .select_from(bs) .join(v_2, onclause=(bs.version_id == v_2.id)) .join_from(bs_2, Br, onclause=(Br.id == bs_2.branch_id)) ) ..and am

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

2023-03-21 Thread Pierre Massé
Thanks for this quick answer Mike! Obivously, I wasted way to much energy in trying to make everything work with table reflection... :( Let's say I gained experience from it. Regarding the origin of the impression I might have gotten, I'd say I tried to read a big chunk of the docs (unified

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

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

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

2023-03-21 Thread Pierre Massé
Dear all, I am quite new to ORMs and SQLAlchemy, and I have a maybe somewhat naive question set regarding how to build an application around a database. Just a few words of context (may not yield importance, but who knows): I am building a mobile app, for which the server side will be an AWS

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

2023-03-20 Thread Mike Bayer
OK, not really, you want tables in the FROM clause. use either the select_from() or join_from() method to do that: https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#explicit-from-clauses-and-joins On Mon, Mar 20, 2023, at 5:16 PM, 'Dan Stromberg [External]' via sqlalchemy wrote: >

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