[sqlalchemy] How to properly inherit declarative __table_args__?

2018-03-20 Thread Russell Warren
I'm having trouble with SQLAlchemy throwing the warning "Unmanaged access of declarative attribute" when I try and inherit `__table_args__` with declarative. I've been through the docs here:

Re: [sqlalchemy] joined load inheritance with extra joins.. possible?

2018-03-20 Thread Mike Bayer
I think it would be a lot easier to have the corresponding translation linked off using relationship(). can you work with that? On Tue, Mar 20, 2018 at 9:19 AM, Julien Cigar wrote: > Hello, > > I have an existing CMS-like application which uses joined table >

[sqlalchemy] joined load inheritance with extra joins.. possible?

2018-03-20 Thread Julien Cigar
Hello, I have an existing CMS-like application which uses joined table inheritance at its core. Basically I have a base class Content from which all other classes (Folder, Document, Event, File, ...) inherit.=20 It works wonderfully well. This is my (Postgre)SQL schema if you are=20

Re: [sqlalchemy] create table CheckConstraint

2018-03-20 Thread lone ois
Mike thank you. I think, Use __table_args__ This is the definitive usage. If you can add a sample to the Sqlalchemy documentation. Let beginners avoid using the wrong method and confused. Mike Bayer於 2018年3月19日星期一 UTC+8下午9時27分47秒寫道: > > On Mon, Mar 19, 2018 at 12:52 AM, lone ois

[sqlalchemy] Unable to use SQLAlchemy with Postgres for specific schema

2018-03-20 Thread NA
Hi I am trying on spectrify for converting the table into spectrum table, which is failing because of an error in SQLAlchemy step. Not sure, how to associate metadata for the engine to NOT prefix "public" when using non-public schemas such as "my_schema.temp_table_01". While, I saw few

Re: [sqlalchemy] more granular logging configuration

2018-03-20 Thread Mike Bayer
On Tue, Mar 20, 2018 at 4:15 PM, Uri Okrent wrote: > > On Thursday, March 15, 2018 at 9:11:06 AM UTC-4, Mike Bayer wrote: >> >> use execution events for this, before_cursor_execute tends to be a >> good choice (but not the only one): >> >> >>

Re: [sqlalchemy] Re: Differentiate what raised IntegrityError (fkey not found vs. duplicate pkey)

2018-03-20 Thread Mike Bayer
I can show you where I did something like this for Openstack, which you can use yourself but you need to extricate it from oslo.db, at the very least you can grab the regular expressions right out, if you don't want to use the whole @filters framework:

Re: [sqlalchemy] more granular logging configuration

2018-03-20 Thread Uri Okrent
On Thursday, March 15, 2018 at 9:11:06 AM UTC-4, Mike Bayer wrote: > use execution events for this, before_cursor_execute tends to be a > good choice (but not the only one): > > >

[sqlalchemy] Re: Differentiate what raised IntegrityError (fkey not found vs. duplicate pkey)

2018-03-20 Thread Jonathan Vanasco
Mike will probably chime in with a more correct answer, but... You should be able to figure that out by catching the `sqlalchemy.exc.IntegrityError` error and inspecting the attributes (original error or the text message).

[sqlalchemy] Differentiate what raised IntegrityError (fkey not found vs. duplicate pkey)

2018-03-20 Thread Peter Lai
I'm implementing a recursive upsert operation for an object whose primary key also contains a foreignkey, and I'd like to get some more info from IntegrityError, namely whether integrity was violated because the foreignkey didn't exist (yet) or I am trying to insert a duplicate pkey. In the

Re: [sqlalchemy] overriding/ignoring specific database records

2018-03-20 Thread Jonathan Vanasco
On Tuesday, March 20, 2018 at 11:29:18 AM UTC-4, Mike Bayer wrote: > > > if you just need a different name, rename it: > > my_attr = Column('id_foo__context_a', Integer, ...) > > > SqlAlchemy does everything I need. Thanks Mike! -- SQLAlchemy - The Python SQL Toolkit and Object Relational

[sqlalchemy] Re: base class not inserting correctly on subclass insertion (joined table inheritance)

2018-03-20 Thread peter . lai
Yeah it took me about 3 hours to realize that in my actual code, I made a typo in the __init__ so that I was assigning the uuid to the wrong attribute/column. So embarassing :( On Monday, March 19, 2018 at 11:04:04 PM UTC-4, Peter Lai wrote: > > As seen at: >

Re: [sqlalchemy] base class not inserting correctly on subclass insertion (joined table inheritance)

2018-03-20 Thread Mike Bayer
Hello - I've reproduced your code fragments as a complete MCVE, it runs fine. Please run this script and try to see where your own application differs. from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative

Re: [sqlalchemy] overriding/ignoring specific database records

2018-03-20 Thread Mike Bayer
On Tue, Mar 20, 2018 at 3:02 AM, Jonathan Vanasco wrote: > this is silly - I realized I can just use a flag to run a different > `orm.relationship` on the Admin and Public views: > > if ADMIN: > records = orm.relationship(a.id=b.id) > else: > records

Re: [sqlalchemy] overriding/ignoring specific database records

2018-03-20 Thread Jonathan Vanasco
this is silly - I realized I can just use a flag to run a different `orm.relationship` on the Admin and Public views: if ADMIN: records = orm.relationship(a.id=b.id) else: records = orm.relationship(and(a.id=b.id, b.id<1000)) Is there any magical SqlAlchemy feature