[sqlalchemy] How to test if an object attribute is a relationship

2018-09-06 Thread Jacek Blocki
Is there a stock function to test if an object attribute is a relationship? I have created below function to test it, is there a better solution? def is_relationship(obj, attr): try: p = inspect(getattr(type(obj), attr)).property except (AttributeError, NoInspectionAvailable):

Re: online vs offline produce different "python stack traces" and general question

2018-09-06 Thread HP3
Thank you very much Mike! The older baseline is on v0.9.7 but I am not sure if I can bump it up 'blindly' ... I think all constructs are "vanilla" so maybe it's safe. In my v0.9.7 based model, I used history_meta recipe (slightly modified though). At any rate, after fudging around with some

Re: online vs offline produce different "python stack traces" and general question

2018-09-06 Thread Mike Bayer
On Thu, Sep 6, 2018 at 1:14 PM, HP3 wrote: > Hello, > > As I try alembic (for the first time), I ran into the following stack traces > when attempting to conduct a "nasty" migration. > > I call it "nasty" because the original model was based on sqlalchemy v0.9 + > python 2.7 and the new model is

Re: [sqlalchemy] how to set column default value ?

2018-09-06 Thread Mike Bayer
for ALTER, which is not what you illustrated earlier, server default comparison is turned off by default as it can be unreliable in some cases. Turn it on using compare_server_default=True:

online vs offline produce different "python stack traces" and general question

2018-09-06 Thread HP3
Hello, As I try alembic (for the first time), I ran into the following stack traces when attempting to conduct a "nasty" migration. I call it "nasty" because the original model was based on sqlalchemy v0.9 + python 2.7 and the new model is sqlalchemy v1.2 + python 3.6. ON TOP OF THAT, it's a

Re: [sqlalchemy] how to set column default value ?

2018-09-06 Thread Yingchen Zhang
like this: old model: class TestModel: ip = db.Column(db.INET, nullable=False) new Model: class TestModel: ip = db.Column(db.VARCHAR(), nullable=False, server_default='127.0.0.1') got migration: op.alter_column('test', 'ip', existing_type=postgresql.INET(),

Re: [sqlalchemy] Re: jsonb_agg issue

2018-09-06 Thread Антонио Антуан
Ok, that works almost fine: >>> func.jsonb_agg(literal_column(models.OrderUINTable.name + '.*')) 'jsonb_agg(OrderUIN.*)' The problem is OrderUIN. It must be quoted: jsonb_agg("OrderUIN".*) чт, 6 сент. 2018 г. в 17:44, Антонио Антуан : > Another one fail: >

[sqlalchemy] Re: jsonb_agg issue

2018-09-06 Thread Антонио Антуан
Another one fail: func.jsonb_agg(*models.OrderUINTable.c.values()) - PG error: "function jsonb_agg(integer, text, numeric, text, text, text, text) does not exist" четверг, 6 сентября 2018 г., 17:28:37 UTC+3 пользователь Антонио Антуан написал: > > Hi guys. > I'm using sqlalchemy 1.1.13, want

[sqlalchemy] jsonb_agg issue

2018-09-06 Thread Антонио Антуан
Hi guys. I'm using sqlalchemy 1.1.13, want to construct that query: select o.*, jsonb_agg(ou.*) from "Orders" o left join "OrderUIN" ou on ou."OrderID" = o."OrderID" group by o."OrderID" I tried that options: - func.jsonb_agg(OrderUINTable), got select o.*, jsonb_agg() from "Orders"... Empty

Re: [sqlalchemy] Setting entity related object via related attribute (using init_scalar event)

2018-09-06 Thread Mike Bayer
OK the use case for the init_scalar, and the docs/example do a bad job of explaining this, is to sync up the default value with that of a Core-level default generator.That's not clear so I should improve those docs. On Thu, Sep 6, 2018 at 10:10 AM, Mike Bayer wrote: > On Thu, Sep 6, 2018 at

Re: [sqlalchemy] Setting entity related object via related attribute (using init_scalar event)

2018-09-06 Thread Mike Bayer
On Thu, Sep 6, 2018 at 4:21 AM, Tomáš Sandrini wrote: > Hi, > > I am writing a library where I need to hide (for normal usage, since that > will be 90% use case) the existence of a Parent object, > basically limiting it just to one property and then set the Parent manually > within the Child

Re: [sqlalchemy] how to set column default value ?

2018-09-06 Thread Mike Bayer
On Thu, Sep 6, 2018 at 3:50 AM, Yingchen Zhang wrote: > so, alembic not support `default` ( pgsql create columnn ) ? it does. use server_default."default" in SQLAlchemy refers to a Python-side default. > > 在 2018年9月6日星期四 UTC+8上午12:24:54,Mike Bayer写道: >> >> On Wed, Sep 5, 2018 at 11:51 AM,

[sqlalchemy] Setting entity related object via related attribute (using init_scalar event)

2018-09-06 Thread Tomáš Sandrini
Hi, I am writing a library where I need to hide (for normal usage, since that will be 90% use case) the existence of a Parent object, basically limiting it just to one property and then set the Parent manually within the Child class through this one property. An obvious solution to this would

Re: [sqlalchemy] how to set column default value ?

2018-09-06 Thread Yingchen Zhang
so, alembic not support `default` ( pgsql create columnn ) ? 在 2018年9月6日星期四 UTC+8上午12:24:54,Mike Bayer写道: > > On Wed, Sep 5, 2018 at 11:51 AM, Yingchen Zhang > wrote: > > db.Column('text_column', db.VARCHAR(20), default='test_text', > > server_default='test_text', nullable=True) > > > > but,