Re: [sqlalchemy] Aborted connections

2021-02-28 Thread Mike Bayer
hi - *many* details are not here, database in use, driver, versions, etc.Most people won't be able to help with a problem like this without basic details. As it turns out I can tell you are using MySQL or MariaDB and the error is described at

Re: [sqlalchemy] Can I do Kerberos delegation, ideally constrained, with SQLAlchemy?

2021-02-28 Thread Mike Bayer
which provides this for Flask web applications. > > On Saturday, February 27, 2021 at 6:48:18 PM UTC-5 Mike Bayer wrote: >> __ >> >> >> It's not really a normal pattern in a web application that database >> connections are user-specific. This is usually too

Re: [sqlalchemy] Can I do Kerberos delegation, ideally constrained, with SQLAlchemy?

2021-02-27 Thread Mike Bayer
It's not really a normal pattern in a web application that database connections are user-specific. This is usually too inefficient as it means you're connecting and disconnecting for every click. Typically a web application uses a single password for the whole database, and then any kind

Re: [sqlalchemy] Session.query vs Session().query when session is a scoped_session

2021-02-27 Thread Mike Bayer
There's no difference, but for the best patterns i would instantiate the Session before using it. Modern Session usage in the upcoming 1.4.0 release looks like what you see at https://docs.sqlalchemy.org/en/14/orm/session_basics.html#opening-and-closing-a-session On Sat, Feb 27, 2021, at 1:31

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-26 Thread Mike Bayer
ought out and was inconsistent with how Core worked, and I've wanted for years to resolve that problem. - mike > On Thursday, February 25, 2021 at 2:21:43 PM UTC-8 Mike Bayer wrote: >> __ >> this will be fixed in https://github.com/sqlalchemy/sqlalchemy/issues/5981 >> where

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Mike Bayer
this will be fixed in https://github.com/sqlalchemy/sqlalchemy/issues/5981 where I've reverted entirely some changes to AppenderQuery that made it work more in 2.0 style. As Query is going to be present in 2.0, "dynamic" relationships will remain also as legacy. They are superseded by

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Mike Bayer
this is a bug. however, the Query object is legacy. what is your actual use case? there are better ways to achieve them now. On Thu, Feb 25, 2021, at 3:25 PM, Ahmed wrote: > Hello, > > It seems that SQLAlchemy 1.4.0b3 ignores relationship() query_class > parameter. Here's the snippet

Re: [sqlalchemy] scalars() in 1.4+

2021-02-22 Thread Mike Bayer
the tutorial. The changes can be reviewed at https://github.com/sqlalchemy/sqlalchemy/commit/930e1a89373ff3ee8c35b6696ed6d70502f03566 where we can continue to adjust, but I wanted to change those terms as you've brought my attention to that. On Mon, Feb 22, 2021, at 10:09 PM, Mike Bayer wrote

Re: [sqlalchemy] scalars() in 1.4+

2021-02-22 Thread Mike Bayer
On Mon, Feb 22, 2021, at 8:50 PM, Zsolt Ero wrote: > Hi, > > I'm a bit confused about the scalars() in 1.4+. The "ORM Querying Guide" > introduces it in the very first example, but it says: > "When selecting a list of single-column ORM entities, it is typical to skip > the generation of Row

Re: [sqlalchemy] SQLAlchemy update on mysql updates less row than directly from IDE or command line

2021-02-14 Thread Mike Bayer
looks like you are matching on timestamps. is there a timezone or date truncation issue occurring ? check the timestamps etc. and make sure they match up. Create small test scripts using SQLAlchemy with echo='debug' to see that the rows you expect are matching.your SQL query does not

Re: [sqlalchemy] Batching INSERT statements

2021-02-12 Thread Mike Bayer
ch other? This answer > <https://stackoverflow.com/a/36387887/11750716> seems to suggest > pre-assigning IDs for it to work. > On Friday, February 21, 2020 at 3:49:54 PM UTC+1 Mike Bayer wrote: >> __ >> Hi Vineet - >> >> glad that worked! I'll have to f

Re: [sqlalchemy] Re: SQLAlchemy join/has query with example code

2021-02-07 Thread Mike Bayer
On Sat, Feb 6, 2021, at 8:56 AM, Chris Simpson wrote: > After posting, I have arrived at *a* solution (which might be awful) Please > let me know if this is a bad approach or I'm following the api correctly: > > I have converted this SQL query: > > SELECT COUNT(*) > FROM person > JOIN

Re: [sqlalchemy] event updating sibling objects: commit() vs. flush()

2021-02-05 Thread Mike Bayer
On Fri, Feb 5, 2021, at 6:37 PM, Gord Thompson wrote: > Hi all. While trying to get more fluent with ORM I looked into a solution for > this Stack Overflow question . > For a many-to-one relationship only one child object can have >

Re: [sqlalchemy] Re: Conditional insert in one transaction

2021-02-05 Thread Mike Bayer
SQLAlchemy will wrap that psycopg2 exception underneath IntegrityError (or at least DBAPIError at the bottommost) so you need to catch the SQLAlchemy-specific expression. of course you should also test it with an existing row to make sure it actually catches and works! On Thu, Feb 4, 2021,

Re: [sqlalchemy] Parameterized "Relationships" with Eager Loading Capability

2021-02-04 Thread Mike Bayer
ot; from what it would have been without the additional filter? > > > On Wednesday, September 23, 2020 at 5:07:20 PM UTC-4 Mike Bayer wrote: >> __ >> the warning is not a big deal but you probably dont want to be making these >> classes on the fly. mapping a cla

Re: [sqlalchemy] Re: Conditional insert in one transaction

2021-02-03 Thread Mike Bayer
for inserts, not really. if you want to guard against duplicate, the pattern is use a savepoint (begin_nested()), catch integrity error, then use the new row if someone else inserted it.this is the more performant option as well as opposed to pessimistic locking.

Re: [sqlalchemy] Invalidated Collection

2021-02-03 Thread Mike Bayer
: session.commit() > > Thanks, > Christian > > > > > > On Wednesday, February 3, 2021 at 5:12:30 PM UTC-5 Mike Bayer wrote: >> __ >> the session.commit() method expires all attributes by default: >> >> https://docs.sqlalchemy.org/e

Re: [sqlalchemy] Invalidated Collection

2021-02-03 Thread Mike Bayer
the session.commit() method expires all attributes by default: https://docs.sqlalchemy.org/en/13/orm/session_basics.html#committing your code is organized in an unusual way such that transactions are being committed inside of attribute assignment operations:

Re: [sqlalchemy] Creating column SQLAlchemy property on parent class based on child column property

2021-02-03 Thread Mike Bayer
I think what the OP would have to do is write a UNION, that is: s.query(Child1).filter(Child1.thing == "thing").union( s.query(Child2).filter(Child2.thing == "thing") ) that's how this problem is approached in SQL.With SQLAlchemy, any problem should be solved by considering the desired

Re: [sqlalchemy] SQLAlchemy transaction ID

2021-01-29 Thread Mike Bayer
effectively just use a basic datamanager to post data, > without any need for synchronized transactions... > > Best regards, > Thierry > -- > https://www.ulthar.net -- http://pyams.readthedocs.io > > > Le mer. 27 janv. 2021 à 20:40, Mike Bayer a écrit : >> __

Re: [sqlalchemy] SQLAlchemy transaction ID

2021-01-27 Thread Mike Bayer
warning in your logs all this time though. > > Best regards, > Thierry > -- > https://www.ulthar.net -- http://pyams.readthedocs.io > > > Le mer. 27 janv. 2021 à 19:19, Mike Bayer a écrit : >> __ >> >> >> On Wed, Jan 27, 2021, at 8:32 AM,

Re: [sqlalchemy] FAQ or Feature Ideas for ORM Object and Session

2021-01-27 Thread Mike Bayer
On Wed, Jan 27, 2021, at 1:12 PM, 'Jonathan Vanasco' via sqlalchemy wrote: > I've been working with a handful of SQLAlchemy and Pyramid based projects > recently, and two situations have repeatedly come up: > > 1. Given a SQLAlchemy Object, access the SQLAlchemy Session > 2. Given a SQLAlchemy

Re: [sqlalchemy] mapper on a temporary class

2021-01-27 Thread Mike Bayer
t to long lived classes and not have any backrefs, it should be OK. I'd test it though :)set up a weakref.ref() to your ad-hoc mapper objects and make sure those ref objects get their callback hook invoked. > > > On Tue, Jan 26, 2021 at 8:18 PM Mike Bayer wrote: >> _

Re: [sqlalchemy] SQLAlchemy transaction ID

2021-01-27 Thread Mike Bayer
On Wed, Jan 27, 2021, at 8:32 AM, Thierry Florac wrote: > > Hi, > I'm actually using SQLAlchemy with Pyramid and zope.sqlalchemy packages. > My main database connection is a ZODB connection and, when required, I create > an SQLAlchemy session which is joined to main transaction using this kind

Re: [sqlalchemy] mapper on a temporary class

2021-01-26 Thread Mike Bayer
t; the class would not already have a mapper. Can I pass non_primary=True > anyway, or won’t this work? oh if the class doesn't have a mapper, then defintiely, just make ad-hoc subclasses of it and map to those.vastly easier that way. > > > On Tue, Jan 26, 2021 at 6

Re: [sqlalchemy] mapper on a temporary class

2021-01-26 Thread Mike Bayer
ossible to have these relationships at least as placeholders on the normal class, then it starts to look like you want to make a subclass and map to that with concrete=True. > > > On Tue, Jan 26, 2021 at 6:18 PM Mike Bayer wrote: >> __ >> >> >> On Tue, Jan 26,

Re: [sqlalchemy] mapper on a temporary class

2021-01-26 Thread Mike Bayer
On Tue, Jan 26, 2021, at 3:16 PM, Kent wrote: > Question: if I add a mapper to a class that is only needed temporarily, does > using the mapper compile it along side my "normal" mappers such that I'll > leak memory when I mean for the class to be garbage collected? > > Put another way, can I

Re: [sqlalchemy] Batch-remove (UPDATE) keys in JSONB column

2021-01-25 Thread Mike Bayer
On Mon, Jan 25, 2021, at 4:29 PM, Anders Steinlein wrote: > Hi, > > In PostgreSQL, I have a JSONB column named custom with for instance this > data: {"firmanavn": "Eliksir", "value": 123}. I can do a query such as this > to remove the "firmanavn" key from the column: > > UPDATE contacts SET

Re: [sqlalchemy] Docstring recommendations for SQLalchemy models?

2021-01-25 Thread Mike Bayer
ace, I'd look around at what's been done in that area to see what bases should be covered. > > Any further tips here would be appreciated. > > Samuel Marks > Charity <https://sydneyscientific.org/> | consultancy <https://offscale.io/> > | open-source &l

Re: [sqlalchemy] Docstring recommendations for SQLalchemy models?

2021-01-24 Thread Mike Bayer
r docstrings are a. reading them in source code and b. generating docs with tools that know how to read them. > > (all my code generators go both ways, so you can edit the generated [cli] > code and generate [class] code from it, and edit the [class] code and > generate [cli]

Re: [sqlalchemy] Docstring recommendations for SQLalchemy models?

2021-01-24 Thread Mike Bayer
is regard. We added that parameter many years ago and it may have been perhaps to work around limitations in Sphinx, not really sure. > > Samuel Marks > Charity <https://sydneyscientific.org/> | consultancy <https://offscale.io/> > | open-source <https://gi

Re: [sqlalchemy] Set PostgreSQL default index tablespace

2021-01-24 Thread Mike Bayer
On Sun, Jan 24, 2021, at 9:42 AM, sector119 wrote: > Hello > > Is it possible to set default tablespace for all indexes? > > I know that I cat set it with > Index('my_index', my_table.c.data, postgresql_tablespace='my_tablespace') > > But I want to set set it by default somehow, that when I

Re: [sqlalchemy] Docstring recommendations for SQLalchemy models?

2021-01-24 Thread Mike Bayer
hey there, sorry I hadn't responded to this. is your tool reformatting Python code? I don't see anything "wrong" with it other than the code looks kind of verbose.This would be a matter of personal preference but if it were me I'd want each attribute to have a string description listed

Re: [sqlalchemy] Re: Multi-AZ RDS on AWS, failover and SQLAlchemy

2021-01-20 Thread Mike Bayer
On Wed, Jan 20, 2021, at 5:42 AM, Harry wrote: > With apologies for resuscitating an old thread, I came across this issue last > week, a 15-minute hang while an amazon RDS instance was doing a failover (we > are on SQLA 1.3.22). I need to do some more work on repro-ing the issue but: > >

Re: [sqlalchemy] Not receiving messages posted to the group

2021-01-13 Thread Mike Bayer
when I look at your message I can't see your full google username but based on the first four characters the email may be notobe...@gmail.com ?that email is set up to receive each message. there's no rshep...@appl-ecosys.com listed in the member list.if you've had google set up with a

Re: [sqlalchemy] Adding a foreign key dynamically

2021-01-11 Thread Mike Bayer
On Mon, Jan 11, 2021, at 10:20 PM, RexE wrote: > I'm changing my framework to use the SQLAlchemy declarative system > internally. However, I want to keep the API the same. Here is how users of my > framework declare a foreign key: > > from myframework import Model, Link > > class Bar(Model)

Re: [sqlalchemy] JSON keys order

2021-01-06 Thread Mike Bayer
y > reordering keys. > > > Le mercredi 6 janvier 2021 à 15:31:49 UTC+2, Mike Bayer a écrit : >> __ >> perhaps Python's json encoder does not maintain ordering? I don't know >> either. Can you set echo='debug' on your create_engine() and examine the >>

Re: [sqlalchemy] JSON keys order

2021-01-06 Thread Mike Bayer
perhaps Python's json encoder does not maintain ordering? I don't know either. Can you set echo='debug' on your create_engine() and examine the parameters being passed as well as the data being returned? also I'm not seeing which database backend or driver you're using which may be

Re: [sqlalchemy] how to set target_metadata programatically ?

2021-01-06 Thread Mike Bayer
the reason Alembic puts env.py into your project, rather than having this just be part of Alembic, is so that you can customize it as needed, so it sounds like for everything you're doing you want to be inside of env.py making those changes. On Wed, Jan 6, 2021, at 1:43 AM, Nikola Radovanovic

Re: [sqlalchemy] how to set target_metadata programatically ?

2021-01-05 Thread Mike Bayer
hi there - usually programmatic customization of Alembic is done via the env.py script directly, that is, you would run "alembic revision" normally and it's within your local env.py that you can control how target_metadata is achieved. you can also pass custom options to "alembic revision"

Re: ask for help on best practices when changing table name from uppercase to lowercase

2021-01-05 Thread Mike Bayer
On Tue, Jan 5, 2021, at 9:50 AM, kz...@us.ibm.com wrote: > Thanks mike! > > I understand that it should work when querying over SQLAlchemy API. the > missing part of my use case I forgot to provide is, it only uses > Alembic/SQLAlchemy to manage schema changes, while the actual query may

Re: ask for help on best practices when changing table name from uppercase to lowercase

2021-01-04 Thread Mike Bayer
This is the casing convention of the database and SQLAlchemy does not consider the name to be in "uppercase" or "lowercase" (or even "mixed case") but rather "case insensitive", which really means the name is referred towards without any quoting.When no quoting is applied, there is

Re: [sqlalchemy] Reflected Table FK

2020-12-31 Thread Mike Bayer
A particular column may be constrained by more than one foreign key constraint (although this is very uncommon), and a particular foreign key constraint may be "composite" in that it refers to multiple columns. All primary and foreign key constructs in SQLAlchemy are inherently composite.

Re: [sqlalchemy] Reflected Table FK

2020-12-31 Thread Mike Bayer
regarding "lists of columns", FOREIGN KEY constraints refer to sets of columns between local table and referred table, not just a single pair of columns. That a typical foreign key constraint might only link a single column in the local and referred tables is a special case.an application

Re: [sqlalchemy] Reflected Table FK

2020-12-31 Thread Mike Bayer
hey there - no need to deal with MetaData, Table, etc. just to get information about tables. Have a look at the inspector interface and get the information directly: https://docs.sqlalchemy.org/en/13/core/reflection.html#fine-grained-reflection-with-inspector Table, MetaData etc. objects are

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
ice and organization relationships at >>> all if I've set up FK for them >>> ForeignKeyConstraint( >>> (schema, service_id), >>> (Service.schema, Service.id) >>> ) >>> and >>> ForeignKeyConstraint( >>> (schema, organization_id),

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
> And must I set primaryjoin for service and organization relationships at all > if I've set up FK for them > ForeignKeyConstraint( > (schema, service_id), > (Service.schema, Service.id) > ) > and > ForeignKeyConstraint( > (schema, organization_id), > (Organization.schema, O

Re: [sqlalchemy] Overlapping FK problem

2020-12-28 Thread Mike Bayer
by having foreign() on the Transaction.schema column, that means when you do this: t1 = Transaction() t1.service = some_service() the ORM is being instructed to copy some_service.schema over to t1.schema. Because "foreign" means "this is the column that mirrors the value of a canonical

Re: [sqlalchemy] Multitenancy, filter selects, updates and deletes in do_orm_execute events

2020-12-28 Thread Mike Bayer
ue > ) > ) > return > > Le dimanche 27 décembre 2020 à 11:31:41 UTC+1, Frédéric CLEMENT a écrit : >> Hi Mike, >> Many thanks for your reply, giving a try to it as soon as it will be >> released. >> >> >> >> Le mercredi 23 décembre 2020 à 16:46:53

Re: [sqlalchemy] Multitenancy, filter selects, updates and deletes in do_orm_execute events

2020-12-23 Thread Mike Bayer
/+/2432 for the patch going through testing now. On Wed, Dec 23, 2020, at 10:16 AM, Mike Bayer wrote: > First off I admire your motivation to make that happen, that's all new stuff > and note there's a lot of fixes to the with_loader_criteria() thing that are > sitting in github mas

Re: [sqlalchemy] Multitenancy, filter selects, updates and deletes in do_orm_execute events

2020-12-23 Thread Mike Bayer
First off I admire your motivation to make that happen, that's all new stuff and note there's a lot of fixes to the with_loader_criteria() thing that are sitting in github master right now that will be in 1.4.0b2. The good news is that update() and delete() both support options as well so feel

Re: [sqlalchemy] Implicitly combining columns message

2020-12-22 Thread Mike Bayer
uot; then you would set the concrete=True parameter on the mapping. the three styles of table inheritance mapping including joined, single and concrete are each described at https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/inheritance.html?highlight=concrete# . > > On

Re: [sqlalchemy] Implicitly combining columns message

2020-12-22 Thread Mike Bayer
er to access these two distinct values in your python code. On Tue, Dec 22, 2020, at 1:46 PM, Larry Martell wrote: > So because ServerUtilization has a FK relation to Server they cannot > have any columns with the same name? > > On Tue, Dec 22, 2020 at 1:28 PM Mike Bayer w

Re: [sqlalchemy] Bidirectional Association Proxy: Unexpected behaviour with add vs. delete?

2020-12-22 Thread Mike Bayer
The association proxy currently covers the "creator" use case, that is, a new Item is given, you pass it a "creator" that says, "create a new OrderItem() object and assign to OrderItem.item", but there is no support at the moment for a "deleter" which says, "take the OrderItem and set

Re: [sqlalchemy] Possible error with fully qualified table names

2020-12-22 Thread Mike Bayer
ecommending, therefore, that I not use the *fullname* attribute for this? > > On Tuesday, December 22, 2020 at 1:17:59 PM UTC-5 Mike Bayer wrote: >> __ >> the .fullname attribute is not used directly in SQL statements, when a >> schema or table name requires quoting

Re: [sqlalchemy] Implicitly combining columns message

2020-12-22 Thread Mike Bayer
this error means that your Server class has a column attribute which you would access as Server.updatedDate. Your ServerUtilization subclass has another column attribute which you would also access as ServerUtilization.updatedDate. the problem arises in that ServerUtilization refers to the

Re: [sqlalchemy] Possible error with fully qualified table names

2020-12-22 Thread Mike Bayer
the .fullname attribute is not used directly in SQL statements, when a schema or table name requires quoting the compiler will apply them as needed. from sqlalchemy import Column from sqlalchemy import String from sqlalchemy.dialects import mysql from sqlalchemy.ext.declarative import

Re: [sqlalchemy] Contributing to SQLAlchemy maintenance or source code

2020-12-22 Thread Mike Bayer
Hi Yaakov - we have some introductory material for contributors at https://www.sqlalchemy.org/develop.html and as mentioned in that doc we are lately meeting on gitter (link is in that document) as well as having weekly dev meetings (though we probably are skipping the next two weeks due to

Re: [sqlalchemy] synonym equivalent for core?

2020-12-22 Thread Mike Bayer
hey Michael - What looks to be happening there is you're making an INSERT against the Table object for Event, the columns in this Table object are: "id", "start_date". The Table has no information about "start_time" as that is an ORM construct only. so your first example is equivalent

Re: [sqlalchemy] using @hybrid_property setter in place of table trigger

2020-12-21 Thread Mike Bayer
hey Gord - for any kind of "do DML query X when Y changes", we usually embed those in the flush process using events, most notably the before_insert/after_insert/before_update/after_update events. Important things we are achieving with the ORM include: - all DML, inserts, updates deletes etc.

Re: [sqlalchemy] One to One relation problem [re-open?]

2020-12-18 Thread Mike Bayer
achricht -- > Von: "Sören Textor" > An: "mike...@zzzcomputing.com" > Gesendet: 18.12.2020 16:52:35 > Betreff: Re: [sqlalchemy] One to One relation problem > >> Hi Mike. >> Thanks for answering. I‘ll check it out on monday. >> We use MSSQL2016

Re: [sqlalchemy] One to One relation problem

2020-12-18 Thread Mike Bayer
hey there - these mappings are pretty good, as is always the case I cannot predict why an issue is occurring, or usually even understand the issue, without running the code. your code is pretty runnable with a few imports added so that's great. however adding an assertion for the condition

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-18 Thread Mike Bayer
tains references to several different classes by using the id shared on > the base class. > > Mark Aquino > > *From:* sqlalchemy@googlegroups.com on behalf > of Mike Bayer > *Sent:* Thursday, December 17, 2020 9:32:40 PM > *To:* noreply-spamdigest via sqlalchemy > *Sub

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-17 Thread Mike Bayer
), primary_key=True, default=uuid4()) >> parents = relationship( >> "ParentClass", >> secondary="mix_parent_class_child_class", >> passive_deletes=True, >> ) >> children = relationship(

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-17 Thread Mike Bayer
> (Plus Many other subclasses) > > A Mixer “BaseClassBaseClass” such that child subclassA and subclassB are both > present in mix_base_class_bass_class > > BaseClass has relationships to BaseClass, SubClassA and SubClassB, so you can > access only SubClassAs and SubClassBs

Re: [sqlalchemy] Re: Can't delete cascade many-to-many with polymorphic relationships unless using lazy=dynamic

2020-12-17 Thread Mike Bayer
your examples aren't complete or runnable so I don't really know what the issue is, although having two relationships to the same target class seems a little unusual and I'm not sure why you'd need that. On Thu, Dec 17, 2020, at 6:01 PM, maqui...@gmail.com wrote: > > I think I may have just

Re: [sqlalchemy] HowTo define hybridproperty.expressions referencing relationship attributes

2020-12-17 Thread Mike Bayer
this kind of issue should be approached by thinking in SQL. the reason one wants to use a hybrid property at the class level is so that one could say: session.query(Motorcycle).filter(Motorcycle.weight_of_tires > 30) OK. So what SQL would be needed for that to work?it's actually not

Re: [sqlalchemy] Non auto increment integer primary key

2020-12-16 Thread Mike Bayer
27, in _execute_context > self.dialect.do_executemany( > File "/opt/python/sqlalchemy/dialects/mssql/pyodbc.py", line 412, in > do_executemany > super(MSDialect_pyodbc, self).do_executemany( > File "/opt/python/sqlalchemy/engine/default.py", line 587, in do_exe

Re: [sqlalchemy] Non auto increment integer primary key

2020-12-16 Thread Mike Bayer
since these two columns have a ForeignKey on them, neither should default to using autoincrement behavior within the DDL phase. the error you are getting indicates that when you created a Component() object, one or both of these columns was not provided with an explicit value to be INSERTed.

Re: [sqlalchemy] MySQL group_concat() with both ORDER BY and SEPARATOR

2020-12-15 Thread Mike Bayer
as this involves a MySQL-specific syntax, the easiest way to just make this happen without any hassle is to use literal_column(), such as: q1 = s.query( func.group_concat( literal_column( "DISTINCT lower(`role`.`name`) ORDER BY lower(`role`.`name`) SEPARATOR '|'"

Re: [sqlalchemy] AttributeError: type object has no attribute 'foreign_keys'

2020-12-15 Thread Mike Bayer
t at its table, here's a worst case workaround: # work around SQLAlchemy issue #5774 def get_bac_table(): from myapp import BusinessAreaContact return BusinessAreaContact.__table__ Contact = relationship("Contact", secondary=get_bac_table) > > On Tue, Dec 15, 2020 at 9

Re: [sqlalchemy] AttributeError: type object has no attribute 'foreign_keys'

2020-12-15 Thread Mike Bayer
n > File "/opt/python/sqlalchemy/util/deprecations.py", line 128, in warned > return fn(*args, **kwargs) > File "/opt/python/sqlalchemy/sql/selectable.py", line 932, in _join_condition > constraints = cls._joincond_scan_left_right( > File "/opt/python/sqlalchemy/sql/selectable.py&q

Re: [sqlalchemy] AttributeError: type object has no attribute 'foreign_keys'

2020-12-15 Thread Mike Bayer
hey there - I don't know what that is. Can you share the complete stack trace? that would show me where it is misinterpreting something. thanks! On Tue, Dec 15, 2020, at 7:48 AM, Larry Martell wrote: > I have this model class: > > class BusinessAreaContact(Base): > __tablename__ =

Re: [sqlalchemy] Association table very slow

2020-12-11 Thread Mike Bayer
hey there - that query is not a cartesian product. the child and child_parent tables are linked together in the WHERE clause. I would assume the query here is in fact taking about half a second to run, the problem here is in the composition of Python objects for every row. I am assuming

Re: [sqlalchemy] Connection pooling uses connections rather than sessions

2020-12-09 Thread Mike Bayer
le SessionPool with SQLAlchemy. > We are leveraging the Session object of SQLAlchemy but we would like to use > the driver level pooling instead of SQLAlchemy pool. > Please advise. > > Thanks, > Anupama > > On Monday, October 3, 2011 at 12:23:58 PM UTC-6 Mike Bayer wrote:

Re: [sqlalchemy] Incorrect .id attribute in __repr__ method

2020-12-06 Thread Mike Bayer
hey there - it seems pretty likely that the source of objects you are using, which would be the "query" you refer towards, or some process afterwards by which these objects are assembled into the list you are printing, contains the same object instance multiple times, hence you see the same

Re: [sqlalchemy] Heads up on bizarre SQL Alchemy + pytest + cx_Oracle interaction

2020-12-06 Thread Mike Bayer
Hey there- I did not take it as any kind of dump on SQLAlchemy at all, it's very common that folks are not aware of the boundary between SQLAlchemy and their DBAPI and as it looks like you are having a shared library issue, I'm sure the cx_Oracle folks could give you some guidance and maybe

Re: [sqlalchemy] Heads up on bizarre SQL Alchemy + pytest + cx_Oracle interaction

2020-12-05 Thread Mike Bayer
hey there - this is a cx_Oracle issue. SQLAlchemy knows nothing about Oracle's native libraries. please report it at https://github.com/oracle/python-cx_Oracle/issues I'm sure they'll be glad to help as they are quite responsive. On Sat, Dec 5, 2020, at 1:10 PM, JL Peyret wrote: > I have

Re: [sqlalchemy] constructing `Mapper` objects is slow (≈4 seconds) when running a local test

2020-12-01 Thread Mike Bayer
On Tue, Dec 1, 2020, at 3:16 PM, Bill Finn wrote: > On Tue, Dec 1, 2020 at 7:42 PM Mike Bayer wrote: >>>> do your "tests" each run in separate processes? >>> >>> Heh, is "tests" surrounding in quotes because we're constructing our ent

Re: [sqlalchemy] constructing `Mapper` objects is slow (≈4 seconds) when running a local test

2020-12-01 Thread Mike Bayer
On Tue, Dec 1, 2020, at 11:03 AM, Bill Finn wrote: > Hi Mike, > > Thanks again for the response. > >> do your "tests" each run in separate processes? > > Heh, is "tests" surrounding in quotes because we're constructing our entire > data model for each test? FWIW, we call them integration

Re: [sqlalchemy] constructing `Mapper` objects is slow (≈4 seconds) when running a local test

2020-12-01 Thread Mike Bayer
eature it will produce new kinds of regressions I'm not thinking of which is one of the reasons I'm hesitant. > > On Mon, Nov 30, 2020 at 11:27 PM Mike Bayer wrote: >> __ >> >> >> On Mon, Nov 30, 2020, at 5:17 PM, Bill Finn wrote: >>> Hello! >

Re: [sqlalchemy] constructing `Mapper` objects is slow (≈4 seconds) when running a local test

2020-11-30 Thread Mike Bayer
On Mon, Nov 30, 2020, at 5:17 PM, Bill Finn wrote: > Hello! > > We're running a unit test that includes constructing ≈330 tables & ≈2,000 > columns total in a local PostgreSQL 10.13 database (on disk, not in memory). > After profiling the test, we found that it takes ≈4 seconds to create all

Re: [sqlalchemy] SQL Server, OPENJSON and large blobs of JSON as placeholder bind values

2020-11-30 Thread Mike Bayer
ued function. > > On Monday, November 30, 2020 at 1:52:03 PM UTC-5 Mike Bayer wrote: >> >> >> On Mon, Nov 30, 2020, at 1:39 PM, Paul Harrington wrote: >>> Hi Mike! >>> I guess that I am looking for advice on a 'reasonably good way' to do each >>&

Re: [sqlalchemy] SQL Server, OPENJSON and large blobs of JSON as placeholder bind values

2020-11-30 Thread Mike Bayer
hey there - took a quick look and we don't support anything with variable declarations, multiple statements in a single string, or multiple result sets. All of that is outside of SQLAlchemy expression languages scope. Since what you're doing is extremely specific to a certain database, if

Re: [sqlalchemy] Differences between TableClause insert and Model.__table__ inserts?

2020-11-26 Thread Mike Bayer
e it work (and this API is used much more effectively in 1.4.0). > > On Wednesday, November 25, 2020 at 2:34:36 PM UTC-8 Mike Bayer wrote: >> __ >> technically Table and TableClause are a little bit different but I don't >> think there's any behavioral difference at t

Re: [sqlalchemy] Differences between TableClause insert and Model.__table__ inserts?

2020-11-25 Thread Mike Bayer
her is used? In other words >> from sqlalchemy.sql import table >> >> _foo = table(...) >> conn.execute(_foo.insert(), [{...}, ...]) >> >> Would have the same performance as `conn.execute(Foo.__table__.insert(), >> [{...}, ...])` >> >&g

Re: [sqlalchemy] Differences between TableClause insert and Model.__table__ inserts?

2020-11-25 Thread Mike Bayer
On Wed, Nov 25, 2020, at 10:30 AM, Kata Char wrote: > Hi, sorry if this post is a duplicate, my first one didn't seem to make it. > > I was reading the documentation: > - https://docs.sqlalchemy.org/en/13/core/tutorial.html#execute-multiple > > - >

Re: [sqlalchemy] Bulk Insert Exception Handling

2020-11-23 Thread Mike Bayer
the bulk_save_objects() method will use executemany() if possible but this has no impact on the behavior of a failing row. cx_Oracle wil normally run all the parameter sets inside of executemany() inside of a single transaction and if any parameter set fails, the operation stops. if you'd

Re: [sqlalchemy] object “is already present in this session” when using a new session with older objects

2020-11-20 Thread Mike Bayer
On Thu, Nov 19, 2020, at 6:15 PM, Vinit Shah wrote: > I posted this on StackOverflow a few days ago, but I haven't been able to > figure this one out yet. The original post can be found here: StackOverflow: > object "is already present in this session" >

Re: [sqlalchemy] Setting Foreign Key based on natural key

2020-11-19 Thread Mike Bayer
On Thu, Nov 19, 2020, at 2:03 PM, Steven James wrote: > In general I have set up foreign keys using the following pattern: > > p = session.query(Parent).filter(Parent.natural_key == key).one() > new_child = Child(parent=p) > > This makes a SELECT and an INSERT and is fine, but it gets

Re: [sqlalchemy] schema qualifying Oracle auto-generated queries for the ORM

2020-11-16 Thread Mike Bayer
On Mon, Nov 16, 2020, at 2:58 PM, Terrence-Monroe: Brannon wrote: > > > > > > On Mon, Nov 16, 2020 at 2:45 PM Mike Bayer wrote: >> __ >> >> >> On Mon, Nov 16, 2020, at 1:32 PM, Terrence-Monroe: Brannon wrote: >>> >>

Re: [sqlalchemy] schema qualifying Oracle auto-generated queries for the ORM

2020-11-16 Thread Mike Bayer
On Mon, Nov 16, 2020, at 1:32 PM, Terrence-Monroe: Brannon wrote: > > > On Mon, Nov 16, 2020 at 1:16 PM Mike Bayer wrote: >> __ >> schema name for tables is set using the .schema parameter of the Table >> object. > > yes, Table() is a core concept. I

Re: [sqlalchemy] schema qualifying Oracle auto-generated queries for the ORM

2020-11-16 Thread Mike Bayer
On Mon, Nov 16, 2020, at 12:36 PM, Terrence-Monroe: Brannon wrote: > I've been using the SA ORM for 3 months simply declaring tables as you see > here: > > https://docs.sqlalchemy.org/en/13/orm/tutorial.html#declare-a-mapping > > And then connecting to Oracle via oracle://user:pass@server >

Re: [sqlalchemy] schema qualifying Oracle auto-generated queries for the ORM

2020-11-16 Thread Mike Bayer
schema name for tables is set using the .schema parameter of the Table object. The docs don't state this at once but you are essentially combining the information contained at https://docs.sqlalchemy.org/en/13/core/metadata.html#specifying-the-schema-name with

Re: [sqlalchemy] avoid setting attribute on init and or.reconstructor

2020-11-16 Thread Mike Bayer
in init_on_load, how > could i make this work? > > Cheers, Lars > On Monday, August 7, 2017 at 6:09:08 AM UTC+2 Mike Bayer wrote: >> >> >> On Aug 6, 2017 1:33 PM, "Shane Carey" wrote: >>> Hey Mike, >>> >>> I can expand my ex

Re: [sqlalchemy] MemoryError in VSCode using dtype NVARCHAR(None) for SQL Server NVARCHAR(max)

2020-11-13 Thread Mike Bayer
This is nothing to do with SQLAlchemy directly but take a look at https://github.com/sqlalchemy/sqlalchemy/issues/5334 for a common situation that leads to this issue. On Thu, Nov 12, 2020, at 9:18 PM, J Sherwood wrote: > Hello, > > I am moving an Oracle Database to SQL Server. > > I go

Re: [sqlalchemy] CTEs and ORM objects.

2020-11-10 Thread Mike Bayer
I would need to see the table defs for "docorder" to do this completely. The parents + kids version: # 1. make parents cte parents_cte = session.query(TreeNode).filter(TreeNode.name == "subnode4").cte("parents", recursive=True) p2 = session.query(TreeNode).filter(TreeNode.id ==

Re: [sqlalchemy] CTEs and ORM objects.

2020-11-10 Thread Mike Bayer
do you know what SQL string you want? I can do this quickly if you can send me the exact string. On Tue, Nov 10, 2020, at 1:40 PM, kris wrote: > The example is from adjecency_list.py example. > > The last three lines construct a recursive CTE to walk to the parent from a > found

Re: [sqlalchemy] CTEs and ORM objects.

2020-11-10 Thread Mike Bayer
rt 'result' tuples into class T? >> >> Thanks >> >> >> >> >> >> >> >> >> On Tuesday, November 10, 2020 at 5:46:32 AM UTC-8 Mike Bayer wrote: >>> __ >>> I would advise against using from_statement(). the Qu

Re: [sqlalchemy] CTEs and ORM objects.

2020-11-10 Thread Mike Bayer
I would advise against using from_statement(). the Query object supports cte() and subqueries directly, see the example at https://docs.sqlalchemy.org/en/13/orm/query.html?highlight=query%20cte#sqlalchemy.orm.query.Query.cte alternatively if you are using 1.4 beta1 then you can use

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