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

2023-05-14 Thread Shane Holcombe
I've tested all the ways I could previously trigger the issue and still, no Nones seem to even be produced to be filtered out, that fix definitely seems to have sorted the issue out On Sunday, May 14, 2023 at 7:42:54 AM UTC+10 Shane Holcombe wrote: > Yes so I'm testing the second

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

2023-05-13 Thread Shane Holcombe
; won't make it to the select() statement at the end. > > On Sat, May 13, 2023, at 3:36 AM, Shane Holcombe wrote: > > 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 >

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

2023-05-13 Thread Shane Holcombe
dentities. > -inspect(to_adapt).selectable.c > -self._aliased_class_pool.append(to_adapt) > - > -return self._aliased_class_pool[idx] > - > def _generate_row_adapter( > self, > compile_state, > > > > > On Fri, M

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

2023-05-12 Thread Shane Holcombe
return > > compile_state._append_dedupe_col_collection(c, > column_collection) > > > > can you try that patch ? > > > On Fri, May 12, 2023, at 10:47 PM, Mike Bayer wrote: > > OK, maybe you are onto something with the theory re:

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

2023-05-12 Thread Shane Holcombe
ecute(stmt).scalar_one_or_none() As for the models, we don't really use any default loaders on relationship creation, we've tended to avoid that and put the joins in the select statements we create If you really need to see a particular model from this let me know. Thanks again for the hel

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

2023-05-11 Thread Shane Holcombe
6 or so levels deep, however we never used selectinload or immediateload to my knowledge so there is no way to change the recursion depth. Any help on this would be fantastic, Thanks, Shane -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post examp

Re: [sqlalchemy] SQLAlchemy, Oracle, and Oracle synonyms

2017-09-11 Thread Shane Ó Conchúir
Hi Mike, Sorry for the delay in response - I have not gotten back to this project yet to test your suggestions out. I am not working from reflection currently and may not do so for a couple of reasons. I like your idea of renaming the tables - I was autogenerating the models (it is a large sch

[sqlalchemy] SQLAlchemy, Oracle, and Oracle synonyms

2017-09-05 Thread Shane Ó Conchúir
his a sensible approach? I did try using metadata and reflection to avoid explicitly writing any models but there seemed to be a startup cost in seconds to that when the script ran and it is also useful to have classes to augment with utility functions. Any help is welcome! Regards, Shane --

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 session.query(ChildOne

[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): __ta

[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' id

[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 http://st

[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 w

[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
etPiece.piece_id) \ .filter(or_(Item.calories > 100, Item.pages < 500, Piece.calories > 100, Piece.pages < 500)) \ .all() On Tuesday, April 25, 2017 at 4:36:18 PM UTC-5, Shane Carey wrote: > > I have a self referential polymorphic relationship using single table > inherit

[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 Food(Item):

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

2017-04-03 Thread Shane Carey
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 Parent(Bas

[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 c

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

2017-02-09 Thread Shane Carey
.type_id) AS _sa_polymorphic_on, thing.stuff AS > thing_stuff, 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 tho

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

2017-02-09 Thread Shane Carey
February 9, 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 dis

[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_, eve

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 q

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 object. H

[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 sqlalc

[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

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

2017-02-01 Thread Shane Carey
t SQL. 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, ins

[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() class

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
teger, db.ForeignKey('series.id'), > nullable=False) > series = db.relationship(Series, backref='publications') > __mapper_args__ = { > 'polymorphic_on': select([series.type]).where(series_id == > Series.id).as_scalar(), >

[sqlalchemy] polymorphic_on using relationship discriminator

2017-01-27 Thread Shane Carey
Hi, I want to use a discriminator based upon a column of a related table. I found the relevant place in the docs http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#joined-table-inheritance "The discriminator column is only needed if polymorphic loading is desired, as is usually the case

[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 sqlalch

[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 JSON_E

[sqlalchemy] Re: alchemy-migrate with DeclarativeBase

2010-06-23 Thread Shane
Hi Torsten, How would you define the Account class? Calling create on my DeclarativeBase Account object was one of the first things I tried, but I keep getting: AttributeError: type object 'Account' has no attribute 'create' Maybe a version difference in sqlalchemy? - Sha

[sqlalchemy] Re: alchemy-migrate with DeclarativeBase

2010-06-17 Thread Shane
6:00 am, Francisco Souza wrote: > > Hi , > > > [...] > > > But do I do this?  Part of the problem is that I don't know of a way > > to generate tables other than  create_all() (or drop_all()) when using > > declarative syntax.  Is there another way? > > H

[sqlalchemy] alchemy-migrate with DeclarativeBase

2010-06-16 Thread Shane
.rollback() I like the idea behind migrate, but have been using DeclarativeBase throughout my application. Having to switch between the Table/mapper & Base syntax is a bit awkward, so I am hoping there is a more direct, all DeclarativeBase way of doing things. Thanks for the help, Shane -

[sqlalchemy] Re: Directly saving a dictionary of column values to SA...

2009-10-30 Thread Shane
class attributes? field_type = cols[k].type# This gives me SA types (Integer(), Unicode(length=20), etc) NOT Python types setattr(self, k, field_type(v)) # Won't work. field_type doesn't cast to Python. Getting there, but still messy. - Shane # Need to check types within t

[sqlalchemy] Directly saving a dictionary of column values to SA...

2009-10-30 Thread Shane
.id'), nullable = True) __mapper_args__ = {'polymorphic_identity': 'product'} Ex: line = LineItem() line.saveTG(kw) This works since I am working on the base class, but if I use a ProductLineItem line=ProductLineItem() line.saveTG(kw) If fails since my table contain