[sqlalchemy] can't read the change with mysql in time

2018-12-13 Thread 540690106
I'm using SQLAlchemy, The situation is that the same database is accessed by two different Python services. After service A performs add and commit, new entries can be seen in the database, but service B cannot obtain new data through SQLAlchemy's query, and only through the native mysql

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
To resolve this i try to create proxy object -- 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://stackoverflow.com/help/mcve for a full

[sqlalchemy] General on set event handler

2018-12-13 Thread Daniel Leon
I know that you can define an on set event handler for an attribute using the decorator @event.listens_for(Class.Attribute, 'set'). I'd like a single event handler to handle every attribute on every class. How can I do this? In the event handler I want to refresh the object before setting the

Re: many to many relation with foreign key to composite primary key

2018-12-13 Thread Mike Bayer
I can't reproduce any problem. Filling out your mappings from your first email, these look like: from sqlalchemy import * from sqlalchemy.orm import relationship from datetime import datetime from sqlalchemy.ext.declarative import declarative_base as db target_metadata = MetaData()

Re: many to many relation with foreign key to composite primary key

2018-12-13 Thread patrick payet
Hi Mike, The message has been truncated. The CREATE TABLE statements is : CREATE TABLE users ( id BIGSERIAL NOT NULL, email VARCHAR(100) NOT NULL, name VARCHAR(100) NOT NULL, hashed_password VARCHAR(100) NOT NULL, is_admin BOOLEAN, is_active

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Mike Bayer
maybe clearer class Address(object): def __init__(self, name, value, towndetail): self.name = name self.value = value self.towndetail = towndetail @classmethod def __composite_constructor__(cls, name, value, town_name, town_value): """given name, value, name, value return

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
test_instance.street_address.town_detail.name = 'tataa' after create now work, is it normal? -- 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

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
That's perfect when have not > 3k tables and dont need load compound columns and relationships when called) Without that for create with orm i need ~ 200s with SSD and ~ 60 seconds to load all relationships)) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
That is my fault, sorry) -- 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://stackoverflow.com/help/mcve for a full description. --- You received

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Mike Bayer
On Thu, Dec 13, 2018 at 8:40 AM Tolstov Sergey wrote: > > Here is my example, how to get arond decorator classmethod (without it not > work, self.__class__ instead of Address not override this function) sure that works too, the docstring now says "any callable" so sure the approach I've

Re: many to many relation with foreign key to composite primary key

2018-12-13 Thread Mike Bayer
On Thu, Dec 13, 2018 at 7:11 AM patrick payet wrote: > > Hi Mike, > Thanks for your answer. > My problem it’s a classical problem for application development, I want to > make authentication and authorisation for a web application. > I want to understand why Alembic can’t create the model in

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
Here is my example, how to get arond decorator classmethod (without it not work, self.__class__ instead of Address not override this function) session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker( bind=engine, autoflush=False)) def make_dump(obj): return json.dumps(

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Mike Bayer
On Thu, Dec 13, 2018 at 8:20 AM Tolstov Sergey wrote: > > I cannot undestand, why you use @classmethod? it's an alternate constructor that accepts a, b, c, d as arguments, rather than name, value, towndetail. it's @classmethod because there is no instance of Address when it is called. it's

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Mike Bayer
On Thu, Dec 13, 2018 at 2:08 AM Tolstov Sergey wrote: > > Thanks, Not so bad as expected) Can you add this example to official docs? magic https://docs.sqlalchemy.org/en/latest/orm/composites.html?highlight=composite#nesting-composites > > среда, 12 декабря 2018 г., 20:33:05 UTC+3

Re: [sqlalchemy] composite type nested

2018-12-13 Thread Tolstov Sergey
I cannot undestand, why you use @classmethod? среда, 12 декабря 2018 г., 20:33:05 UTC+3 пользователь Mike Bayer написал: > > composites of composites aren't supported directly so you'd have to > map out all the columns for "street" directly, then define a > constructor that handles the columns:

Re: many to many relation with foreign key to composite primary key

2018-12-13 Thread patrick payet
Hi Mike, Thanks for your answer. My problem it’s a classical problem for application development, I want to make authentication and authorisation for a web application. I want to understand why Alembic can’t create the model in autogeneration mode and how modify this model to resolve this problem.