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

2017-08-06 Thread Shane Carey
Hey Mike, I can expand my example. I have an orm mapped attribute like this class Obj(Base): _evaluator = Column(String) def __init__(self, **kwargs): super().__init__(**kwargs) self._eval_func = eval(self._evaluator) @orm.reconstructor def init_on_load(self):

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

2017-08-04 Thread Shane Carey
I am trying to remove duplicate code in this scenario described here http://docs.sqlalchemy.org/en/latest/orm/constructors.html class Obj(Base): def __init__(self, **kwargs): super().__init__(**kwargs) self.extra = # ... some complicated construction based off of a kwarg

[sqlalchemy] Re: inline polymorphic_load for single table inheritance

2017-07-14 Thread Shane Carey
Okay, I understand that. My example isnt actually the best for the question I am asking. Say I have three subclasses ChildOne, ChildTwo, ChildThree is there a way to query for ChildOne and ChildTwo in one query, or do I need to filter on the discriminator? something like

[sqlalchemy] Re: inline polymorphic_load for single table inheritance

2017-07-13 Thread Shane Carey
After reading the documentation more thoroughly, I realized that with_polymorphic does not filter the result set by subclasses included, it only eagerly loads the attributes of those subclasses. In order to filter on certain subclasses, am I forced to user Query.filter() for that purpose? --

[sqlalchemy] inline polymorphic_load for single table inheritance

2017-07-13 Thread Shane Carey
When I have single table inheritance, how can I use the new 'inline' polymorphic_load feature to only query a subset of child classes? from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Parent(Base):

[sqlalchemy] Using sql expression to update a column from another table's column

2017-05-10 Thread Shane Carey
Given the following declarative schema, how can I generate the UPDATE statement? I am using MySQL class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) str = Column(String(16), nullable=False) bs = relationship(B) class B(Base): __tablename__ = 'b'

[sqlalchemy] Re: Cannot use func when bulk saving objects

2017-04-28 Thread Shane Carey
I was able to solve this by using a subquery instead of loading and updating, thanks anyway! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

[sqlalchemy] Re: Cannot use func when bulk saving objects

2017-04-28 Thread Shane Carey
I just realized this line in the docs may be what I was missing - SQL expression inserts / updates (e.g. Embedding SQL Insert/Update Expressions into a Flush ) However, I still

[sqlalchemy] Cannot use func when bulk saving objects

2017-04-28 Thread Shane Carey
Hi, I found what I think to be a bug in the bulk save objects method. The following raises an exception: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Obj(Base): __tablename__ = 'obj_bulk_test' id

[sqlalchemy] Re: Filter on self referential polymorphic relationship

2017-04-25 Thread Shane Carey
A more complete example: from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import * Base = declarative_base() class Item(Base): __tablename__ = 'item' id = Column(Integer, primary_key=True) type = Column(String) __mapper_args__ = { 'polymorphic_on': type,

[sqlalchemy] Re: Filter on self referential polymorphic relationship

2017-04-25 Thread Shane Carey
:18 PM UTC-5, Shane Carey wrote: > > I have a self referential polymorphic relationship using single table > inheritance > > Base = declarative_base() > > class Item(Base): > __tablename__ = 'item' > id = Column(Integer) > type = Column(String) > >

[sqlalchemy] Filter on self referential polymorphic relationship

2017-04-25 Thread Shane Carey
I have a self referential polymorphic relationship using single table inheritance Base = declarative_base() class Item(Base): __tablename__ = 'item' id = Column(Integer) type = Column(String) __mapper_args__ = { 'polymorphic_on': type, 'with_polymorphic': '*'} class

Re: [sqlalchemy] Delete orphan occurs even before commit happens and when expunge happens

2017-04-03 Thread Shane Carey
on the autoflush? I simply need to stop all changes to my parent from being persisted, without rolling back the session. On Monday, April 3, 2017 at 9:47:13 AM UTC-5, Mike Bayer wrote: > > > > On 04/03/2017 09:52 AM, Shane Carey wrote: > > I am getting an error where delete orphan

[sqlalchemy] Delete orphan occurs even before commit happens and when expunge happens

2017-04-03 Thread Shane Carey
I am getting an error where delete orphan on a relationship seems to happen even when the parent object is expunged. I reproduced the issue in this example. from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import * Base = declarative_base() class

[sqlalchemy] Re: Status of cascading polymorphism, in docs as well

2017-02-22 Thread Shane Carey
Works great for me On Tuesday, February 21, 2017 at 2:56:58 PM UTC-6, Shane Carey wrote: > > I understand from the docs and several questions both here and on > bitbucket that cascading polymorphism is not supported. This > is what it says on the docs: > > Warning > &

[sqlalchemy] Status of cascading polymorphism, in docs as well

2017-02-21 Thread Shane Carey
I understand from the docs and several questions both here and on bitbucket that cascading polymorphism is not supported. This is what it says on the docs: Warning Currently, *only one discriminator column may be set*, typically on the base-most class in the hierarchy. “Cascading” polymorphic

Re: [sqlalchemy] Polymorphic 'all' query with discriminator surrogate key gives subquery multiple row error

2017-02-09 Thread Shane Carey
uff, thing.junk AS thing_junk > FROM thing INNER JOIN type ON type.id = thing.type_id > WHERE type.type = %(type_2)s > > noting that this query is not going to scale up to millions of rows that > well as MySQL hates those subqueries. > > > > > > > > On 02/09/

Re: [sqlalchemy] Polymorphic 'all' query with discriminator surrogate key gives subquery multiple row error

2017-02-09 Thread Shane Carey
, 2017 at 10:02:40 AM UTC-6, Mike Bayer wrote: > > > > On 02/09/2017 10:14 AM, Shane Carey wrote: > > Hi, another question. > > > > I set my discriminator on the surrogate primary key of its table. > > However, when I query for all of a certain discriminator

[sqlalchemy] Polymorphic 'all' query with discriminator surrogate key gives subquery multiple row error

2017-02-09 Thread Shane Carey
Hi, another question. I set my discriminator on the surrogate primary key of its table. However, when I query for all of a certain discriminator, I get an error 'Multiple rows returned for subquery'. Here is my canonical example from sqlalchemy import * from sqlalchemy import select, and_,

Re: [sqlalchemy] Can I create a query and associate it with a session later?

2017-02-09 Thread Shane Carey
Works great, and thanks for the update to the documentation. On Wednesday, February 8, 2017 at 4:48:32 PM UTC-6, Mike Bayer wrote: > > > > On 02/08/2017 05:40 PM, mike bayer wrote: > > > > > > On 02/08/2017 05:31 PM, Shane Carey wrote: > >> This is an

[sqlalchemy] Can I create a query and associate it with a session later?

2017-02-08 Thread Shane Carey
This is an artificial example but it would help my application become more modular if I could pass a Query object to my session. I see in the docs it says "Query objects are normally initially generated using the

Re: [sqlalchemy] Session.enable_relationship_loading with inline select statement

2017-02-02 Thread Shane Carey
inject the select execution directly into the model? On Thursday, February 2, 2017 at 8:55:06 AM UTC-6, Mike Bayer wrote: > > > > On 02/02/2017 09:29 AM, Shane Carey wrote: > > Hi, I have a use case where I need to enable relationship loading on a > > single objec

[sqlalchemy] Session.enable_relationship_loading with inline select statement

2017-02-02 Thread Shane Carey
Hi, I have a use case where I need to enable relationship loading on a single object. However, I initialize the foreign key of this relationship using an inline select statement. from sqlalchemy import * from sqlalchemy import select, and_, event, inspect from sqlalchemy.orm import * from

[sqlalchemy] Re: Duplicate primary key while merging polymorphic relationship

2017-02-01 Thread Shane Carey
I resolved this issue, it was a misconfiguration of my 'polymorphic_on' On Wednesday, February 1, 2017 at 8:35:59 AM UTC-6, Shane Carey wrote: > > I took the SQL into mysql directly to see what may be going wrong, it > looks like the generated > > SELECT > thing.id AS thing_i

[sqlalchemy] Re: Duplicate primary key while merging polymorphic relationship

2017-02-01 Thread Shane Carey
. On Wednesday, February 1, 2017 at 8:14:06 AM UTC-6, Shane Carey wrote: > > I am having a strange issue with merging a polymorphic relationship, I've > managed to reduce my problem to this code: > > from sqlalchemy import * > from sqlalchemy import select, and_, event, inspect > from

[sqlalchemy] Duplicate primary key while merging polymorphic relationship

2017-02-01 Thread Shane Carey
I am having a strange issue with merging a polymorphic relationship, I've managed to reduce my problem to this code: from sqlalchemy import * from sqlalchemy import select, and_, event, inspect from sqlalchemy.orm import * from sqlalchemy.ext.declarative import * Base = declarative_base()

Re: [sqlalchemy] polymorphic_on using relationship discriminator

2017-01-31 Thread Shane Carey
Thanks for you help, Mike! On Monday, January 30, 2017 at 10:36:06 AM UTC-6, Mike Bayer wrote: > > > > On 01/30/2017 11:06 AM, Shane Carey wrote: > > Thanks for the help! I was able to get this working with > > > > select([Series.type]).where(Series.id == seri

Re: [sqlalchemy] polymorphic_on using relationship discriminator

2017-01-30 Thread Shane Carey
False) > series = db.relationship(Series, backref='publications') > __mapper_args__ = { > 'polymorphic_on': select([series.type]).where(series_id == > Series.id).as_scalar(), > 'polymorphic_identity': None > } > > > > > On 01/27/201

[sqlalchemy] Re: JSON_EXTRACT with tuple generates incorrect SQL on MYSQL 5.7

2016-10-06 Thread Shane Carey
I am running SQLAlchemy 1.1.0 -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to

[sqlalchemy] JSON_EXTRACT with tuple generates incorrect SQL on MYSQL 5.7

2016-10-06 Thread Shane Carey
Hi all, I've encountered an error with filtering by JSON values on MYSQL 5.7. My code: def MyClass: __tablename__ = 'my_class' data = Column(JSON) keys = ('code',) val = ('val',) query = session.query(MyClass).filter(MyClass.data[keys].in_(val)).all() generates the SQL snippet