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

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

Re: [sqlalchemy] SQLAlchemy 1.4 / 2.0 distribution

2021-07-14 Thread Mike Bayer
on third party library > (aiopg) which should be compatible with SQLAlchemy 1.4 too but there some > problems with it ( > https://github.com/aio-libs/aiopg/issues/798#issuecomment-879815102 ) which > make migration from 1.3 to 1.4 impossible for now =/ > > On Thursday,

Re: [sqlalchemy] 'ResultProxy' object has no attribute 'description'

2021-07-02 Thread Mike Bayer
I'm not familiar with this issue and would need to see a complete stack trace and preferably a simple test script (MCVE) as well, but at the very least a stack trace, as well as SQLAlchemy version in use, database dialect / driver in use. thanks. On Fri, Jul 2, 2021, at 2:31 PM, Larry Martell

Re: [sqlalchemy] Automatically add Index on same columns in ForeignKeyConstraint in Postgresql using Custom DDL/Compilation

2021-06-25 Thread Mike Bayer
On Fri, Jun 25, 2021, at 11:58 AM, mkmo...@gmail.com wrote: > > When using PostgreSQL, creating a foreign key on a column in a table does not > automatically index that column, unlike Oracle or MySQL. > > I would like to get SQLAlchemy to automatically create an index on the same > columns

Re: [sqlalchemy] Lose the schema??

2021-06-21 Thread Mike Bayer
https://github.com/sqlalchemy/sqlalchemy/issues/6658 will be fixed in the next release though your program should not have to use the IDENTITY INSERT feature and we need to see your schema / Table. On Mon, Jun 21, 2021, at 5:57 PM, Mike Bayer wrote: > OK more specifically you s

Re: [sqlalchemy] Lose the schema??

2021-06-21 Thread Mike Bayer
er dialect that does not correctly combine "schema_translate_map" with IDENTITY INSERT. however there is no reason IDENTITY INSERT should be changing here, I would need to see the "CREATE TABLE" for this table as well as what your Table metadata looks like. On Mon, Jun 21, 2021

Re: [sqlalchemy] Lose the schema??

2021-06-21 Thread Mike Bayer
you have a Table that defines "schema" as "SCHEMA__none", and this schema does not exist. Schema definition is described at https://docs.sqlalchemy.org/en/14/core/metadata.html#specifying-the-schema-name . On Mon, Jun 21, 2021, at 4:34 PM, Victor Manuel Arévalo Fandiño wrote: > Hello > >

Re: [sqlalchemy] migrating to 1.4 and sql.and_()

2021-06-21 Thread Mike Bayer
per.py#L117-L130 > (2) https://gist.github.com/silenius/34ce40ed288c6a681058ab064147bd70 > (3) https://gist.github.com/silenius/02a8c2481f77ca1a1ec05bfad830821d > (4) https://gist.github.com/silenius/5de95ceddd14e62bfc3e52366643bd32 > > Julien > > On Fri, Jun 18, 2021 at 10:11:

Re: [sqlalchemy] migrating to 1.4 and sql.and_()

2021-06-18 Thread Mike Bayer
that's a really obscure API you found there. Coverage for that wasn't carried along to 1.4 unfortunately so you'd need to assemble that list outside of the and_() first for now. On Fri, Jun 18, 2021, at 4:08 AM, Julien Cigar wrote: > Hello, > > While updating SQLAlchemy dependency

Re: [sqlalchemy] Ambiguous joins, relationships, and aliases

2021-06-17 Thread Mike Bayer
On Thu, Jun 17, 2021, at 1:04 PM, Dane K Barney wrote: > I have scoured the documentation looking for the preferred way of handling > ambiguous joins, and it seems to be through use of aliased tables, but I > still wonder if there's a better way. Intuitively, it seems like > relationships

Re: [sqlalchemy] versioned_history example uses deprecated Column.copy() method

2021-06-16 Thread Mike Bayer
HI Simon - I believe that example for now should vendor its own "copy()" function that does what's needed. the function that's there is already un-doing some of the work of the old copy() method in any case. I think for history table we need column name, datatype, and maybe nullable

Re: [sqlalchemy] checking in

2021-06-14 Thread Mike Bayer
discussion has mostly moved to github discussions: https://github.com/sqlalchemy/sqlalchemy/discussions at the same time there are a few emails per day here still, i just answered at least two or three since yesterday. On Mon, Jun 14, 2021, at 5:25 PM, Rich Shepard wrote: > I've not worked

Re: [sqlalchemy] Logging handler logic

2021-06-14 Thread Mike Bayer
seeing this discrepancy, I was concerned > about what I may overlook and end up finding out the hard way. > > Thanks, > jlc > > On Sunday, June 13, 2021 at 1:06:11 PM UTC-6 Mike Bayer wrote: >> __ >> the line you refer towards involves a flag called "echo"

Re: [sqlalchemy] Logging handler logic

2021-06-13 Thread Mike Bayer
the line you refer towards involves a flag called "echo", which is described at https://docs.sqlalchemy.org/en/14/core/engines.html#more-on-the-echo-flag and is entirely optional. if you don't use the echo flag, SQLAlchemy's logging behavior is completely traditional, with the caveat that the

Re: [sqlalchemy] No NOWAIT for FOR UPDATE

2021-06-13 Thread Mike Bayer
hi you need to compile with the postgresql dialect, see https://docs.sqlalchemy.org/en/14/faq/sqlexpressions.html#stringifying-for-specific-databases from sqlalchemy import column from sqlalchemy import table from sqlalchemy.dialects import postgresql from sqlalchemy.future import select t =

Re: [sqlalchemy] Session and optimistic disconnect handling

2021-06-10 Thread Mike Bayer
PM, 'Matt Zagrabelny' via sqlalchemy wrote: > > > On Tue, Jun 8, 2021 at 11:58 AM Mike Bayer wrote: >> __ >>> >>> Unknown network failures, I suppose. I have an application that is throwing >>> an exception right now due to: >>> >

Re: [sqlalchemy] SQLAlchemy 1.4 / 2.0 distribution

2021-06-10 Thread Mike Bayer
undreds of users have already done so. The 1.3-> 1.4 change is roughly comparable to the change that it has been for other releases, like 1.0->1.1, 1.1->1.2 etc. > > On Thursday, June 10, 2021 at 2:10:48 AM UTC+3 Mike Bayer wrote: >> __ >> hi there - >>

Re: [sqlalchemy] SQLAlchemy 1.4 / 2.0 distribution

2021-06-09 Thread Mike Bayer
hi there - having a separate project name on pypi doesn't solve any issue that isn't already solved by using version pinning - the "sqlalchemy" name on pypi is already at 1.4. the only way to install 1.3 is by requesting "pip install sqlalchemy < 1.4". As you've probably seen, SQLAlchemy 1.4

Re: [sqlalchemy] Session and optimistic disconnect handling

2021-06-08 Thread Mike Bayer
On Tue, Jun 8, 2021, at 12:40 PM, 'Matt Zagrabelny' via sqlalchemy wrote: > > > On Tue, Jun 8, 2021 at 10:28 AM Mike Bayer wrote: >> __ >> >>> >>>> however, I would advise using pool_pre_ping instead which is much easier >>>> to use

Re: [sqlalchemy] Session and optimistic disconnect handling

2021-06-08 Thread Mike Bayer
On Tue, Jun 8, 2021, at 11:18 AM, 'Matt Zagrabelny' via sqlalchemy wrote: > Hi Mike, > > Thanks for the reply! > > On Mon, Jun 7, 2021 at 6:08 PM Mike Bayer wrote: >> __ >> ORM Sessions ride on top of connections, but since the Session under it's >&g

Re: [sqlalchemy] Session and optimistic disconnect handling

2021-06-07 Thread Mike Bayer
ORM Sessions ride on top of connections, but since the Session under it's default pattern of being bound to an Engine does the "connect" internally, it's probably inconvenient to adapt the optimistic disconnect approach to it. You would probably want to bind the Session to the Connection

Re: [sqlalchemy] issue with hybrid properties

2021-05-28 Thread Mike Bayer
the hybrid here is pulling in additional tables which are causing a cartesian product since there is nothing joining the Document entity to this other entity which seems to be DocumentTranslation.Run this in 1.4 and you will see the warnings generated. an ORDER BY etc. has to either

Re: [sqlalchemy] Location of "string lookup" for classes in a declarative base?

2021-05-27 Thread Mike Bayer
limited case there's no reason the information *has* to come from the > internal sqlalchemy registry. > > Thanks again, > Brendan > > On Thu, May 27, 2021 at 11:36 AM Mike Bayer wrote: >> __ >> we haven't made a public APi for this however the discussion of wha

Re: [sqlalchemy] Location of "string lookup" for classes in a declarative base?

2021-05-27 Thread Mike Bayer
we haven't made a public APi for this however the discussion of what it would look like is at https://github.com/sqlalchemy/sqlalchemy/issues/6080 and the proposal is at https://github.com/sqlalchemy/sqlalchemy/issues/6080#issuecomment-801253683. What you can do now is use

Re: [sqlalchemy] When to set "cache_ok" to True?

2021-05-26 Thread Mike Bayer
ribute to `False`? > > On Wed, May 26, 2021 at 5:54 AM Mike Bayer wrote: >> __ >> >> >> On Wed, May 26, 2021, at 3:07 AM, niuji...@gmail.com >> <mailto:niuji...%40gmail.com> wrote: >>> I have consistently receiving the warning: >>> will not pro

Re: [sqlalchemy] Multiple mappers found by get_mapper - model inheritance

2021-05-26 Thread Mike Bayer
i wrote: > It's from sqlalchemy_utils - > https://sqlalchemy-utils.readthedocs.io/en/latest/orm_helpers.html#get-mapper > > śr., 26 maj 2021 o 17:47 Mike Bayer napisał(a): >> __ >> get_mapper() is not part of SQLAlchemy where is it? >> >> On Wed, May 26, 2021, at 9:35 A

Re: [sqlalchemy] Multiple mappers found by get_mapper - model inheritance

2021-05-26 Thread Mike Bayer
tity_descriptor. In > get_mapper this seems to hit the "if isinstance(mixed, sa.Table):" branch and: > > if mixed in mapper.tables > > ends true to all 3 of them as it's either the parent or child that inherits > it. > > > > > > śr., 26 maj 2021 o 15:21 Mike Ba

Re: [sqlalchemy] Multiple mappers found by get_mapper - model inheritance

2021-05-26 Thread Mike Bayer
I would need to see what get_mapper() is doing. the best way to associate the relevant table to a mapper is to look at inspect(Class).mapper.local_table. On Wed, May 26, 2021, at 9:18 AM, Piotr wrote: > I'm updating "sqlalchemy_django_query" for SQLAlchemy 1.4 and aside of that I > found a

Re: [sqlalchemy] When to set "cache_ok" to True?

2021-05-26 Thread Mike Bayer
On Wed, May 26, 2021, at 3:07 AM, niuji...@gmail.com wrote: > I have consistently receiving the warning: > will not produce a cache key because the ``cache_ok`` flag is not set to > True. Set this flag to True if this type object's state is safe to use in a >

Re: [sqlalchemy] Updating sqlalchemy_django_query to sqlalchemy 1.4

2021-05-21 Thread Mike Bayer
eError: Multiple mappers > found for table* ). Seems like using 10-year old abandoned code that uses > SQLAlchemy internals wasn't the best long term idea ;) > > czw., 20 maj 2021 o 16:06 Mike Bayer napisał(a): >> __ >> _compile_state() is an expensive call so you'd want to

Re: [sqlalchemy] Updating sqlalchemy_django_query to sqlalchemy 1.4

2021-05-20 Thread Mike Bayer
commit/6fab64bb0f31e2e3f3e1ed82269fd26464f00aba > > I used *self._compile_state()._joinpoint_zero()* while > *self._filter_by_zero() *also seems to be working.** > > czw., 20 maj 2021 o 01:41 Mike Bayer napisał(a): >> __ >> the _joinpoint_zero() can likely be replaced by _filter_by_zero() : >> h

Re: [sqlalchemy] Aldjemy many to many modeling

2021-05-19 Thread Mike Bayer
On Wed, May 19, 2021, at 7:34 PM, Ryan Hiebert wrote: > I maintain Aldjemy, a library that converts Django models into SQLAlchemy > models. I'm having some trouble figuring out how I should resolve an issue > I'm working on, and I could use your help. Here's the link to the issue I'm >

Re: [sqlalchemy] Updating sqlalchemy_django_query to sqlalchemy 1.4

2021-05-19 Thread Mike Bayer
the _joinpoint_zero() can likely be replaced by _filter_by_zero() : https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/orm/query.py#L1697 I had mentioned this to someone on twitter but they never got back to me if it worked or not. On Wed, May 19, 2021, at 7:19 AM, Piotr

Re: [sqlalchemy] Binding a connection to a SQLAlchemy session object

2021-05-17 Thread Mike Bayer
and the Session will begin/commit/rollback on that connection. > On Monday, May 17, 2021 at 3:08:34 PM UTC-6 Mike Bayer wrote: >> >> >> On Mon, May 17, 2021, at 4:21 PM, Anupama Goparaju wrote: >>> Hi, >>> >>> I see in the documentation >>

Re: [sqlalchemy] Binding a connection to a SQLAlchemy session object

2021-05-17 Thread Mike Bayer
On Mon, May 17, 2021, at 4:21 PM, Anupama Goparaju wrote: > Hi, > > I see in the documentation > that we can bind > a connection to a SQLAlchemy session object: > > *# at the module level, the global sessionmaker,* *# bound to a

Re: [sqlalchemy] inserted_primary_key in version 1.4.

2021-05-15 Thread Mike Bayer
ny single-row inserts must impose > an enormous performance penalty, whereas retrieving the ids via a subsequent > SELECT would have to rely on the specifics of the inserted data (which may > not be unique). > > On Thursday, May 13, 2021 at 7:29:42 PM UTC-7 Mike Bayer wrote: &g

Re: [sqlalchemy] inserted_primary_key in version 1.4.

2021-05-13 Thread Mike Bayer
So the use case you are doing there was never something supported, and in particular the value you are getting on 1.3 is not really universally reliable, as it is relying upon cursor.lastrowid that is not defined for multiple-row inserts, even though for InnoDB specifically the behavior is

Re: [sqlalchemy] Rationale for why 1.4 Core `select` argument as list is deprecated?

2021-05-13 Thread Mike Bayer
> > Matthew > > On Thursday, May 13, 2021 at 5:54:21 AM UTC-7 Mike Bayer wrote: >> __ >> SQLAlchemy has a general philosophy of fn(*args) vs fn(list): >> >> 1. if the sequence of items represents **database data**, we use a **list** >> or other inlin

Re: [sqlalchemy] Rationale for why 1.4 Core `select` argument as list is deprecated?

2021-05-13 Thread Mike Bayer
SQLAlchemy has a general philosophy of fn(*args) vs fn(list): 1. if the sequence of items represents **database data**, we use a **list** or other inline sequence. E.g. in_(): column.in_([1, 2, 3]) 2. if the sequence of items represents **SQL structure**, we use a variable length

Re: [sqlalchemy] Re: Unique Partial Indexes throwing UniqueViolation

2021-05-12 Thread Mike Bayer
not silly at all, it's kind of an unfortunate situation w/ postgresql's naming, the name 'postgres' might be worth hardcoding somehwere as a universal "warn" kind of thing just so it doesn't skip silently On Wed, May 12, 2021, at 11:45 AM, Michael Bukachi wrote: > Typo alert. It's supposed to

Re: [sqlalchemy] MX Linux Python3 sqlalchemy hangs on ROLLBACK

2021-05-11 Thread Mike Bayer
sword@127.0.0.1/options') > > And that appears to handle that particular insert without issue. > > Thank-you, > > Rob > On Tuesday, May 11, 2021 at 10:41:13 AM UTC-4 Mike Bayer wrote: >> __ >> two things to try: >> >> 1. try a different driver, like mysql

Re: [sqlalchemy] MX Linux Python3 sqlalchemy hangs on ROLLBACK

2021-05-11 Thread Mike Bayer
two things to try: 1. try a different driver, like mysqlclient or pymysql, to see if error persists 2. when it hangs, look in information_schema.processlist for current info (it's the same in mariadb): https://dev.mysql.com/doc/refman/8.0/en/information-schema-processlist-table.html On

Re: [sqlalchemy] IDLE vs checked in connection

2021-05-08 Thread Mike Bayer
: 0 > create conn1 > [('active',)] > Pool size: 5 Connections in pool: 0 Current Overflow: -4 Current Checked out > connections: 1 > create conn2 > [('active',)] > Pool size: 5 Connections in pool: 0 Current Overflow: -3 Current Checked out > connections: 2 >

Re: [sqlalchemy] IDLE vs checked in connection

2021-05-08 Thread Mike Bayer
On Sat, May 8, 2021, at 11:05 AM, Mike Bayer wrote: > >> ** >> I was wondering if: >> 1. There was a reason for this difference in behaviour? Should a checked-in >> connection show up as 'IDLE'? > > I would check your methodology of measurement because

Re: [sqlalchemy] IDLE vs checked in connection

2021-05-08 Thread Mike Bayer
On Sat, May 8, 2021, at 10:34 AM, sumau wrote: > Hello > > Our postgreSQL database is suffering from too many IDLE connections and I'm > wondering if this has to do with isolation level which we usually set to > AUTOCOMMIT. that's not really possible as AUTOCOMMIT "isolation" merely means

Re: [sqlalchemy] Unexpected TypeError when using `choices` as parameter name to TypeDecorator

2021-05-06 Thread Mike Bayer
ame to that conclusion, and I agree that replacing it with a > tuple does fix it, but I still can't explain why using a different parameter > name also fixes it. > > On Thursday, 6 May 2021 at 11:46:53 UTC-4 Mike Bayer wrote: >> __ >> this is a regression in SQLAlchemy in that

Re: [sqlalchemy] Unexpected TypeError when using `choices` as parameter name to TypeDecorator

2021-05-06 Thread Mike Bayer
this is a regression in SQLAlchemy in that the TypeDecorator is being applied to caching without giving the end user any clue or API to control this process. the name "choices" is not significant, it's that the parameter as given is trying to be part of a cache key, so turn this into a tuple

Re: [sqlalchemy] SQLAlchemy error when autogenerating documentation for database module using pdoc3

2021-05-05 Thread Mike Bayer
On Wed, May 5, 2021, at 11:18 AM, Yaakov Bressler wrote: > *But when I try generating documentation for the entire project > **(`MODULE='.'`)**, I get the following error:* > > ImportError: Error importing 'PROJECT_NAME.database': > InvalidRequestError: Table 'FooBar' is already defined for

Re: [sqlalchemy] Changing Type of an ORM record

2021-05-03 Thread Mike Bayer
On Mon, May 3, 2021, at 12:31 PM, Richard Damon wrote: > > > Ok, understand. Maybe my application is a bit unusual, but it seems I > will be doing this a LOT. > that's fine, you'll make a function to do what you need and use it everywhere > > In my case nothing will REALLY be the base >

Re: [sqlalchemy] Changing Type of an ORM record

2021-05-02 Thread Mike Bayer
On Sun, May 2, 2021, at 4:44 PM, Richard Damon wrote: > I asked this a bit ago, but never got an answer, so trying again wording > a bit different to see if I can get help. sorry if this got missed. > > The question is, given an existing record for an 'Employee', how to I > change it from an

Re: [sqlalchemy] Callback for when orm data is load

2021-04-27 Thread Mike Bayer
in before run_created > is called. > > listen(mapper, 'load', self.load_instance) > listen(mapper, 'refresh', self.refresh_instance) > > > > On 4/27/21 1:20 PM, Mike Bayer wrote: >> the event that corresponds most directly here is the do_orm_execute() even

Re: [sqlalchemy] Callback for when orm data is load

2021-04-27 Thread Mike Bayer
the event that corresponds most directly here is the do_orm_execute() event: https://docs.sqlalchemy.org/en/14/orm/session_events.html#session-execute-events you would want to use the "re-execute statement" feature described at:

Re: [sqlalchemy] Table Reflection Error

2021-04-24 Thread Mike Bayer
On Fri, Apr 23, 2021, at 5:38 PM, Jeff Griffin wrote: > Using sqlalchemy 1.4.5 and pymssql 2.1.5, I am reflecting an Oracle Table > from one database (Oracle) and attempting to create it in a second database > (MS SQL Server). On table.create I get the following error: > > Compiler can't

Re: [sqlalchemy] compiler tutorial questions

2021-04-21 Thread Mike Bayer
in > the class construct, as in the AlterColumn example I think this is just basic Python programming > -replace print(str(s)) with print(s) (unless there's some difference I'm not > aware off) probably a good idea. > > Let me know if you would like me to raise a merge reque

Re: [sqlalchemy] compiler tutorial questions

2021-04-21 Thread Mike Bayer
olumn.column_name, AddColumn.column_type) > > s = AddColumn(users,'col1', 'int') > print(str(s)) > > with engine.connect() as conn: > conn.execute(AddColumn(users,'col1', 'int')) > print(conn.execute(users.select()).fetchall()) > Regards > Soumaya > >

Re: [sqlalchemy] correct usage of next_value for a sequence

2021-04-20 Thread Mike Bayer
On Tue, Apr 20, 2021, at 1:52 PM, 'Matt Zagrabelny' via sqlalchemy wrote: > Greetings SQLAlchemy, > > I'm attempting to use the next_value function to get the (next) value from a > sequence: > > cycle_counter = next_value(Sequence('cycle_seq')) > print(cycle_counter) > >

Re: [sqlalchemy] compiler tutorial questions

2021-04-19 Thread Mike Bayer
On Mon, Apr 19, 2021, at 2:09 PM, sumau wrote: > Hello > > I'm trying to understand compilation and working through the compiler > tutorial: https://docs.sqlalchemy.org/en/14/core/compiler.html > > I was hoping for some clarification : > > 1) What is the difference between starting your

Re: Managing multiple tenant "namespaces"

2021-04-16 Thread Mike Bayer
On Fri, Apr 16, 2021, at 7:15 AM, Nikola Radovanovic wrote: > Hi, > we have one Postgres DB with multiple schemes: > 1. general (one schema, contains users and some common and data shared > between clients/clusters) > 2. client schemes: c_client_1, c_client_2, c_client_3, etc. (all clients >

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
> for molecule in molecules: > session.delete(molecule) > orphan_chains = ( > session.query(TestChain).filter(~TestChain.molecules.any()).all() > ) > for orphan_chain in orphan_chains: > orphan_chain.var_regions.clear() > orphan_chain.const_regions.clear() > se

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
s.delete(c1) s.commit() > > > > > > It works as expected with deleting the molecule, and test_molecule_chain rows > are removed but not test_chains hence why I need to perform the additional > logic to remove the stranded chains that are left behind but not linked

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-14 Thread Mike Bayer
.chains.add(light_chain_1) > > light_chain_1_sequence = TestMolSequence(content="taglconst1VAR1") > heavy_chain_1_sequence = TestMolSequence(content="tagheavyconstant1VAR2") > heavy_chain_2_sequence = TestMolSequence(content="tagheavyconstant2VAR2") >

Re: [sqlalchemy] Issue with "complex" many 2 many delete, FK violation

2021-04-13 Thread Mike Bayer
Hi there - I would ask that you try to make sure your formatting is maintained when posting examples especially such long ones as I had to re-indent it in order to run this. The delete at the end is failing because of incomplete cascade rules. The DELETE against "test_mol_sequence" seeks to

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-13 Thread Mike Bayer
ombine getattr > with the documentation as below? > > class Student(Model): > __table__ = Table("Students", metadata, autoload=True, > autoload_with=engine) > first_period = getattr(__table__.c, "1st_period") > > Thanks, > Rob > On Mon

Re: [sqlalchemy] How to refer to columns whose names begin with a number when autoloading?

2021-04-12 Thread Mike Bayer
besides the idea of using getattr(), as these are object attributes it's probably a good idea to name them differently from those columns. See the docs at https://docs.sqlalchemy.org/en/14/orm/mapping_columns.html#naming-columns-distinctly-from-attribute-names for strategies on how to achieve

Re: [sqlalchemy] Comparing an SQLAlchemy object to a similar object

2021-04-12 Thread Mike Bayer
option #1 seems much simpler I'd likely start with that re uuid, I usually take the "existing" ids and put them in a dictionary so I know which ones to skip, absolutely. I don't understand what the "list comprehension" approach would entail that isn't using a hash lookup of some kind. On

Re: Managing multiple tenant "namespaces"

2021-04-09 Thread Mike Bayer
On Wed, Apr 7, 2021, at 5:18 AM, Nikola Radovanovic wrote: > Hi, > I have a bit unusual use-case in software I work on. > > There are three main "namespaces" (kinds of data): first one is "general" > (not multi-tenant), where we keep some common security and settings data. > > Second one is

Re: [sqlalchemy] autocommit Transaction Isolation Level

2021-04-04 Thread Mike Bayer
t;> c = > >>> create_engine('postgresql://***:***@localhost:5432/postgres').connect() > >>> c.execute(text('select * from test')).fetchall() > [] > > Thanks > Soumaya > > > > > > > Le jeu. 1 avr. 2021 à 18:33, Soumaya Mauthoor a > écri

Re: [sqlalchemy] autocommit Transaction Isolation Level

2021-04-01 Thread Mike Bayer
ct() as conn: conn.execute(text('create table test(int > >>> col1)')) > ... > > >>> e.execute('select * from test').fetchall() > [] > > I didn't commit the transaction, but it seems to have autocommited since I > can query it in the following query? >

Re: [sqlalchemy] autocommit Transaction Isolation Level

2021-04-01 Thread Mike Bayer
On Thu, Apr 1, 2021, at 10:06 AM, sumau wrote: > Hello > > Following advice from this article: > https://www.oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/ > > and because we run large, consecutive queries, we set our transaction > isolation level to 'autocommit' when connecting to

Re: [sqlalchemy] How to handle multiple relationships between tables properly with automap?

2021-04-01 Thread Mike Bayer
I've just adjusted the logic for this warning for the upcoming 1.4.5 release. A description of the warning is here: https://docs.sqlalchemy.org/en/14/errors.html#relationship-x-will-copy-column-q-to-column-p-which-conflicts-with-relationship-s-y it looks like automap is generating

Re: [sqlalchemy] Baked Query with Bound Entity/FromClause

2021-03-31 Thread Mike Bayer
On Wed, Mar 31, 2021, at 12:37 PM, Scott Colby wrote: > Hello, > > I have a bunch of tables with created_at columns and I would like to bake > queries to retrieve counts of rows from them. > > def _entities_created(model: Model, before: datetime) -> int: > baked_query = BAKERY(lambda

Re: [sqlalchemy] Columns error migrating to autoload_with

2021-03-25 Thread Mike Bayer
the constructor for Table is not expecting that you pass the "name" and "metadata" argument as keyword arguments and this is causing the reflection process to not occur at all. specify the table like this: Table('my_table', metadata, schema='test_schema', autoload_with=engine) There's some

Re: [sqlalchemy] Delay in accessing table with 2 enum columns using asyncpg + ORM

2021-03-25 Thread Mike Bayer
gt;>>> 0.00055s] ('ONE',) >>>>> 2021-03-25 18:26:24,274 DEBUG sqlalchemy.engine.Engine Col ('id',) >>>>> 2021-03-25 18:26:24,275 DEBUG sqlalchemy.engine.Engine Row (1,) >>>>> 2021-03-25 18:26:24,276 INFO sqlalchemy.engine.Engine COMMIT >&

Re: [sqlalchemy] Delay in accessing table with 2 enum columns using asyncpg + ORM

2021-03-25 Thread Mike Bayer
environment, I also attempted to run > (dockerised) python in the same Ubuntu 20.04.2 virtual machine but that too > is showing the delay. > On Thursday, 25 March 2021 at 15:57:17 UTC+1 Mike Bayer wrote: >> __ >> so with PG12 and python 3.7 you *do* or *do not* see the slowdo

Re: [sqlalchemy] Columns error migrating to autoload_with

2021-03-25 Thread Mike Bayer
hi there - would need a complete example and SQLAlchemy version in use, Table does have a "_columns" attribute and both patterns described below are things that should work without an error like this, additionally the complete stack trace would also be helpful. Unpickling the metadata is a

Re: [sqlalchemy] Delay in accessing table with 2 enum columns using asyncpg + ORM

2021-03-25 Thread Mike Bayer
> * Python 3.7 > So far no dice. This was all within docker though, I'll try a few more things > outside of the docker environment and report back. > > On Thursday, 25 March 2021 at 14:02:29 UTC+1 Mike Bayer wrote: >> __ >> Hi there - >> >> thanks for

Re: [sqlalchemy] Delay in accessing table with 2 enum columns using asyncpg + ORM

2021-03-25 Thread Mike Bayer
Hi there - thanks for the clear example. I just ran it against a several PG databases, including a PG 13 and PG 12 on the local network, and I am not observing any delay of that magnitude, SQL output with timestamps follow. what OS are you running on ? I would say you might want to

Re: [sqlalchemy] AttributeError: Neither 'QueryableAttribute' object nor 'Comparator' object has an attribute '__visit_name__'

2021-03-24 Thread Mike Bayer
hi - that's a bug!The .params() method is kind of forgotten. https://github.com/sqlalchemy/sqlalchemy/issues/6124 is added, however this is not a regression since this is using new functionality on select(). I think I have a fairly straightforward fix for this however it won't be in

Re: [sqlalchemy] (cx_Oracle.DatabaseError) ORA-00972

2021-03-22 Thread Mike Bayer
can you please include the SQLAlchemy version and Oracle version in use? as well as an example Table model. These issues should be resolved for Oracle, the label names are truncated automatically. On Mon, Mar 22, 2021, at 8:28 AM, Aurèle Durand wrote: > Hello, > > SqlAchemy automatically

Re: [sqlalchemy] Using Abstract Base Classes with ORM Table Classes

2021-03-15 Thread Mike Bayer
you no longer have to use DeclarativeMeta at all, you can use a class decorator: https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#declarative-mapping-using-a-decorator-no-declarative-base if you are on 1.3, there's a way to get the same effect in 1.3 using the instrument_declarative

Re: [sqlalchemy] Relationship between two models without constraints or cascades

2021-03-14 Thread Mike Bayer
ry: https://docs.sqlalchemy.org/en/14/orm/relationship_api.html?highlight=passive_deletes#sqlalchemy.orm.relationship.params.passive_deletes On Sun, Mar 14, 2021, at 10:27 AM, Mike Bayer wrote: > > > On Sun, Mar 14, 2021, at 7:49 AM, Jack Matthews wrote: >> The database I am trying to mai

Re: [sqlalchemy] Relationship between two models without constraints or cascades

2021-03-14 Thread Mike Bayer
On Sun, Mar 14, 2021, at 7:49 AM, Jack Matthews wrote: > The database I am trying to maintain is a representation of a configuration > file I have scraped from a network device. I have two models that when both > exist in the configuration are related to each other, but it is also possible >

Re: [sqlalchemy] Foriegn key from one database to another in SQLAlchemy or Alembic

2021-03-14 Thread Mike Bayer
When you want to have objects in different databases in the same server have SQL interactions, you use one engine and then schema-qualify the tables using the "schema" argument: https://docs.sqlalchemy.org/en/14/core/metadata.html#specifying-the-schema-name if OTOH you are talking about two

Re: [sqlalchemy] Extensible Generation

2021-03-10 Thread Mike Bayer
I would go with "subclassing" but don't map the base class immediately, use a mixin instead - there's examples of this at https://docs.sqlalchemy.org/en/14/orm/declarative_mixins.html . to ensure the relationships are against the target class, declare them like this: class MyMixin:

Re: [sqlalchemy] Aborted connections

2021-03-10 Thread Mike Bayer
On Wed, Mar 10, 2021, at 5:39 AM, William Edwards wrote: > Thanks for your response. So, when calling close() on an SQLAlchemy > connection, it is returned to the connection pool, but the MySQL connection > is not actually closed. That makes sense. > > Could you elaborate on your comment

Re: branch merge schema conflict

2021-03-09 Thread Mike Bayer
just so you know, surgical-precision downgrades will be more reliable once we get the 1.6 series of Alembic out, where we have a total rewrite of how the internal traversal works in order to make upgrade/downgrades across complex trees more reliable. downgrades are not *too* common in

Re: branch merge schema conflict

2021-03-09 Thread Mike Bayer
On Tue, Mar 9, 2021, at 5:06 PM, 'br...@derocher.org' via sqlalchemy-alembic wrote: > I'm wondering how to solve an issue. > > One developer created migration 1efb > > upgrade: > drop view v1 -- moved to query in the code > > downgrade: >create view v1 as select 1 > > Another

Re: [sqlalchemy] can you insert data for a model with a many to many relationship using alembic?

2021-03-09 Thread Mike Bayer
bulk_insert_mappings doesn't handle relationships in any case, if you wanted relationships to be persisted without doing the INSERT yourself you would need to use regular ORM Session unit of work patterns. In Alembic, you would need to use ORM mappings inside of your alembic scripts, which is

Re: [sqlalchemy] Exception on '.refresh' for certain objects - state.load_path Tuple is empty

2021-03-09 Thread Mike Bayer
update attempts earlier. > Thank you > On Monday, March 8, 2021 at 4:38:13 PM UTC-5 Mike Bayer wrote: >> __ >> it looks like a bug unless you are manipulating the InstanceState. I would >> upgrade to SQLAlchemy 1.3.23 first to make sure it hasn't been fixed. >> >&g

Re: [sqlalchemy] Exception on '.refresh' for certain objects - state.load_path Tuple is empty

2021-03-08 Thread Mike Bayer
it looks like a bug unless you are manipulating the InstanceState. I would upgrade to SQLAlchemy 1.3.23 first to make sure it hasn't been fixed. On Mon, Mar 8, 2021, at 1:09 PM, Gmoney wrote: > On python 3.7 SQLAlchemy 1.3.13 > I'm running into an issue when doing a

Re: [sqlalchemy] Supporting Function Indexes on a Minimum Sqlite Version

2021-03-08 Thread Mike Bayer
On Mon, Mar 8, 2021, at 12:06 PM, 'Jonathan Vanasco' via sqlalchemy wrote: > I have a project that, in a few rare situations, may run on a version of > sqlite that does not support function indexes, and "need" to run a unique > index on `lower(name)`. For simplicity, I'll just use a normal

Re: [sqlalchemy] 2.0 Migration: Transaction Scope Performance Pitfalls

2021-03-05 Thread Mike Bayer
On Fri, Mar 5, 2021, at 11:00 AM, Jonathan Brandmeyer wrote: > > > On Fri, Mar 5, 2021 at 8:29 AM Mike Bayer wrote: >> __ >> Can I ask what documentation led you to believe that engine.connect() was >> somehow being removed ? > > The guidance at [1] m

Re: [sqlalchemy] 2.0 Migration: Transaction Scope Performance Pitfalls

2021-03-05 Thread Mike Bayer
performance with engine.begin(). however, there is no need to change existing code that uses engine.connect() / connection.begin(). On Fri, Mar 5, 2021, at 10:29 AM, Mike Bayer wrote: > OK this is not hard to understand, in one case you are connecting fresh from > the connection pool eac

Re: [sqlalchemy] 2.0 Migration: Transaction Scope Performance Pitfalls

2021-03-05 Thread Mike Bayer
SQLAlhcemy 2.0. Can I ask what documentation led you to believe that engine.connect() was somehow being removed ? On Fri, Mar 5, 2021, at 12:02 AM, Jonathan Brandmeyer wrote: > > > On Thu, Mar 4, 2021 at 5:00 PM Mike Bayer wrote: >> hey there- >> >> engine.begin

Re: [sqlalchemy] 2.0 Migration: Transaction Scope Performance Pitfalls

2021-03-04 Thread Mike Bayer
hey there- engine.begin() does not do anything to the SQLite connection at all as there is no begin() method in the Python DBAPI. this is why in your logging you will see a line that says "BEGIN (implicit)". nothing happened. the pysqlite driver controls the scope of the actual BEGIN on the

Re: [sqlalchemy] Postgres Row Level Security (RLS)

2021-03-04 Thread Mike Bayer
this is a highly postgresql-specific set of commands so using op.execute() with the ALTER commands you need seems to be the most direct and obvious way to achieve this, I'm not sure what the downside would be?if it's the redundancy, simply create a function in your applicaiton that is given

Re: [sqlalchemy] Using `INSERT...ON CONFLICT` with ORM

2021-03-02 Thread Mike Bayer
ng if ORM way of handling the conflict during the insert was ever > implemented after this discussion. > On Sunday, February 19, 2017 at 8:00:31 AM UTC-8 Mike Bayer wrote: >> >> >> On Feb 17, 2017 2:00 PM, "Calvin Young" wrote: >>> Michael, >>&

Re: [sqlalchemy] SQLAlchemy 1.3.23 turn off before_compile with **kwargs?

2021-03-01 Thread Mike Bayer
the before_compile event receives the Query object at the point it starts to turn it into a SQL construct. When this happens, it's in response to having said something like "query.all()". So there's no **kwarg that's specific to an operation like that. instead, when you want to send

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-03-01 Thread Mike Bayer
ion in particular https://docs.sqlalchemy.org/en/14/changelog/migration_14.html and https://docs.sqlalchemy.org/en/14/changelog/migration_20.html > > A. > > On Fri, Feb 26, 2021, 5:18 PM Mike Bayer wrote: >> __ >> >> >> On Fri, Feb 26, 2021, at 8:0

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