[sqlalchemy] connection in a different thread can't read tables created in another thread?

2022-01-11 Thread niuji...@gmail.com
In a testing suite I have a fixture that drop all the tables in an engine, then start fresh and create all the tables. After this fixture logic, my test case runs, using the newly created table. The fixture and the test case are run in the MainThread, while the database consumer is a web

Re: [sqlalchemy] @declared_attr.cascading doesn't work when inheritance of multiple levels

2021-11-28 Thread niuji...@gmail.com
nt to look at "cls" with inspect(cls).local_table etc. > and figure out the correct column to include in the FK if you are doing > things this way. > > > > > > > > On Sun, Nov 28, 2021, at 4:22 PM, niuji...@gmail.com wrote: > > I've just manually put this line

Re: [sqlalchemy] @declared_attr.cascading doesn't work when inheritance of multiple levels

2021-11-28 Thread niuji...@gmail.com
) On Sunday, November 28, 2021 at 8:25:30 AM UTC-8 Mike Bayer wrote: > > > On Sun, Nov 28, 2021, at 4:24 AM, niuji...@gmail.com wrote: > > I'm using the "joined table inheritance" model. I have three levels of > inheritance. > > class has_polymorphic_id(object): >

[sqlalchemy] @declared_attr.cascading doesn't work when inheritance of multiple levels

2021-11-28 Thread niuji...@gmail.com
I'm using the "joined table inheritance" model. I have three levels of inheritance. class has_polymorphic_id(object): @declared_attr.cascading def record_id(cls): if has_inherited_table(cls): return Column(ForeignKey('employee.record_id'),

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
> select(select().scalar_subquery()), and then to produce "SELECT * FROM > (SELECT ) FROM ", that FROM part has to be added on > explicitly, i.e. select(select().scalar_subuqery()).select_from( table>). > > > > On Wed, Nov 10, 2021, at 2:35 PM, niuji...@gma

Re: [sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
ct_from(C) > > > > On Wed, Nov 10, 2021, at 4:50 AM, niuji...@gmail.com wrote: > > class A(Base): > primary_id = Column(Integer, prirmary_key=True) > some_A_marker = Column(String) > > class B(Base): > primary_id = Column(Integer, primary_key=True) >

[sqlalchemy] correlated subquery as column_property can't be queried independently?

2021-11-10 Thread niuji...@gmail.com
class A(Base): primary_id = Column(Integer, prirmary_key=True) some_A_marker = Column(String) class B(Base): primary_id = Column(Integer, primary_key=True) referencing_A_id = Column(Integer, ForeignKey(A.primary_id)) class C(Base): primary_id = Column(Integer,

[sqlalchemy] Is "uselist=False" imcompatible with lazy='joined' in relationship?

2021-10-22 Thread niuji...@gmail.com
Although the official documentation is very robust and detailed, one thing I noticed is not very clear. When specifying arguments for a relationship like this: class Bonus(Base): basis = relationship("Accomplishment", uselist=False, lazy='joined') whenever there is

Re: [sqlalchemy] Is there an event hook for putting a class into class_registry?

2021-10-09 Thread niuji...@gmail.com
, line 106, in get_property_name_from_column return sqlalchemy.inspect(cls).get_property_by_column(column_obj).key File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/orm/mapper.py", line 1998, in get_property_by_column return self._columntoproperty[column] AttributeE

Re: [sqlalchemy] Is there an event hook for putting a class into class_registry?

2021-10-08 Thread niuji...@gmail.com
: > > > On Fri, Oct 8, 2021, at 7:09 AM, niuji...@gmail.com wrote: > > In order to make sure that the mapped class is fully ready, I chose the > latest point, namely `class_instrument`. > However, it seems that at that moment the `__mapper__` attribute is not > available. &g

Re: [sqlalchemy] Is there an event hook for putting a class into class_registry?

2021-10-08 Thread niuji...@gmail.com
> to happen for mapped classes before they are reconciled against other > classes: > > > https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.before_mapper_configured > > > On Wed, Oct 6, 2021, at 4:48 AM, niuji...@gmail.com wrote: > &

[sqlalchemy] Is there an event hook for putting a class into class_registry?

2021-10-06 Thread niuji...@gmail.com
I want to do some after processing on each class that is just put into the class_registry. Is there a event hook for this? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and

[sqlalchemy] 'validates' include_removes=True doesn't seem to prevent deletion?

2021-10-04 Thread niuji...@gmail.com
I have the following validator: @sa_orm.validates('variant_names', include_removes=True) def validate_unique_identifying(self, key, name_dict, is_remove): if is_remove: raise ValueError("DOn't") else: if

Re: [sqlalchemy] Can `sqlalchemy.orm.validates` be set on multiple attributes?

2021-10-01 Thread niuji...@gmail.com
p 3, 2021, at 4:07 PM, niuji...@gmail.com wrote: > > In the official documentation it says: > > > *validates* > <https://docs.sqlalchemy.org/en/13/orm/mapped_attributes.html#sqlalchemy.orm.validates>(*names, > > **kw) > > Decorate a method as a ‘validator’ for

Re: [sqlalchemy] recursive cte use current row as anchor

2021-09-26 Thread niuji...@gmail.com
s only possible with the most recent SQLAlchemy 1.4.24 release where > someone contributed a new parameter called "nesting", which means the CTE > should not be moved to the top level of the SELECT. still, not really > sure what a CTE will do inside a correlated subquery like tha

Re: [sqlalchemy] recursive cte use current row as anchor

2021-09-26 Thread niuji...@gmail.com
assumed to be on the outside. > > give those a try but im not totally sure CTEs work as correlated > subqueries right now, it's not been tried. I assume you've confirmed this > query actually runs, im surprised you can even correlate inside of a CTE > like that. > >

Re: [sqlalchemy] recursive cte use current row as anchor

2021-09-24 Thread niuji...@gmail.com
olumns in the row > is the "effective_enabling_factor". that column needs to be written as a > correlated subquery for it to be compatible with column_property(). > > > > On Fri, Sep 24, 2021, at 1:47 AM, niuji...@gmail.com wrote: > > class Staff(Base)

[sqlalchemy] recursive cte use current row as anchor

2021-09-23 Thread niuji...@gmail.com
class Staff(Base): id = Column(Integer, primary_key=True) selfreferencing_staff_id = Column( Integer, ForeignKey('staff_table.id', onupdate="CASCADE", ondelete='SET NULL')) _enabling_factor = Column(Integer)

[sqlalchemy] Can `sqlalchemy.orm.validates` be set on multiple attributes?

2021-09-03 Thread niuji...@gmail.com
In the official documentation it says: validates (*names, **kw) Decorate a method as a ‘validator’ for one or more named properties. I need to validate two incoming *-**attributes at the same time, for

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

2021-05-26 Thread niuji...@gmail.com
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 cache key, or False to disable this warning. After reading the documentation, I learned that the

Re: [sqlalchemy] conditionals inside column_property

2020-12-11 Thread niuji...@gmail.com
://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.case > >> > >> I think it would look something like this: > >> > >> from sqlalchemy.sql import case > >> > >> aggr = column_property( > >> case([(attr_a ==

[sqlalchemy] conditionals inside column_property

2020-12-11 Thread niuji...@gmail.com
I have a mapped class: class Model(sqlalchemy.declarative_base()): attr_a = Column(String) attr_b = Column(Integer) attr_c = Column(Integer) aggr = column_property(attr_b + attr_c IF attr_a=='go' ELSE attr_b - attr_c) Last line is pseoudo code that requires some conditional