Re: [sqlalchemy] Re: Postgres Composite Columns

2017-09-18 Thread Tolstov Sergey
8, 2017 at 2:30 AM, Tolstov Sergey <whist...@gmail.com > > wrote: > >> Hi, i have some issue. I tried to replace namedtuple to dict and list > >> items (with adding hast function to them). But SQLAlchemy types returns > list > >> ordereddict, when i

[sqlalchemy] Re: Postgres Composite Columns

2017-09-18 Thread Tolstov Sergey
> > Hi, i have some issue. I tried to replace namedtuple to dict and list > items (with adding hast function to them). But SQLAlchemy types returns > list ordereddict, when i change items, session didn't see changes. Do you > found solution? > def make_hash(o): if

Re: [sqlalchemy] Strict many-to-many

2017-10-05 Thread Tolstov Sergey
> > Thanks, that's really good With thanks, Sergey Tolstov -- 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

[sqlalchemy] Strict many-to-many

2017-10-04 Thread Tolstov Sergey
I have some tables who have a strict many-to-many rules. But i can't undestand, how i can create rules for them. For strict on one point i use init check, such us: def __init__(self,**kwargs): for i in kwargs.items():setattr(self,i[0],i[1]) if 'AllocationResultValues' not in kwargs:

Re: [sqlalchemy] SQLALchemy lazy compile classes

2017-10-16 Thread Tolstov Sergey
Thanks for answer, but that's a flask application. And it will run with different args. If i tried to append objects with new relations python raise errors metadata -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

[sqlalchemy] SQLAlchemy many-to-many Postgresql double delete

2017-09-29 Thread Tolstov Sergey
I try to delete data, but sqlalchemy tried to do it twice, and rollback Base Postgresql version 9.6 sqlalchemy 1.0.14 psycopg2 2.7.3.1 class IdentifiedObject(Base): __tablename__ = 'identifiedobject' mRID = Column(UUID, server_default=sqlalchemy.text("uuid_generate_v4()"),

[sqlalchemy] Re: SQLAlchemy many-to-many Postgresql double delete

2017-09-30 Thread Tolstov Sergey
Mike, thanks for answer. But that's not true. I use them on project and it works. Ilja Everilä on StackOverflow help me. Answer is: I need a create functions. In [6]: def class_name_collection(base, local_cls, referred_cls,

[sqlalchemy] SQLALchemy lazy compile classes

2017-09-28 Thread Tolstov Sergey
i haven't found solution for this. Problem in very load compile (40 sec). I have a : - more then 1200 classes - 300 enums - and some custom primitive classes for working - 7 levels of polymorphic inherits - some itself relationship, may one-to-many and many-to-many in one class to itself -

[sqlalchemy] Re: Tracking new relationships

2017-12-01 Thread Tolstov Sergey
Solved, SQlalchemy create object based on instance, i didn't guess that, 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

[sqlalchemy] Tracking new relationships

2017-11-30 Thread Tolstov Sergey
Hi, everyone. I cannot found information how to find information about new relationships, when they related with secondary table. Inspect can't work with class RelationshipProperty. class_mapper.iterate_properties have't information about changed attributes My *task* is: Write

[sqlalchemy] Cancel update and delete before commit

2017-12-08 Thread Tolstov Sergey
I need to *switch off changing* (not new) database rows and write all changes to specific table on event "*before_commit*". But when i try to use *config.session.rollback()* SqlAlchemy show me *AttributeError: 'NoneType' object has no attribute 'transaction'* I try config.session.expunge

Re: [sqlalchemy] Cancel update and delete before commit

2017-12-10 Thread Tolstov Sergey
> > Mike, very thanks for answer. I just use custom function and add to object > session def user_commit(): ... config.session.commit() config.session.user_commit=user_commit -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post

Re: [sqlalchemy] Cancel update and delete before commit

2017-12-10 Thread Tolstov Sergey
Mike, very thanks for answer. I just use custom function and add to object session. I create some lists to save object and after rollback i add them On this func i just use session.dirty, session.new, session.delete for rollback i use def user_commit(): ... config.session.rollback()

Re: [sqlalchemy] Cancel update and delete before commit

2017-12-10 Thread Tolstov Sergey
Mike, very thanks for answer. I just use custom function and add to object session. I create some lists to save object and after rollback i add them On this func i just use session.dirty, session.new, session.delete for rollback i use config.session.rollback() def user_commit(): ...

[sqlalchemy] Re: Transactions

2018-01-08 Thread Tolstov Sergey
вторник, 9 января 2018 г., 9:08:22 UTC+3 пользователь Tolstov Sergey написал: > > I use transactions and sometimes it must be *session.rollback*. > Sometimes i get a AttributeError: 'NoneType' object has no attribute > 'twophase' > That error raises, when one transaction ope

[sqlalchemy] Transactions

2018-01-08 Thread Tolstov Sergey
I use transactions and sometimes it must be *session.rollback*. Sometimes i get a AttributeError: 'NoneType' object has no attribute 'twophase' That error raises, when one transaction open and processed, and *another* transaction with session use *rollback* -- SQLAlchemy - The Python SQL

[sqlalchemy] Re: Transactions

2018-01-08 Thread Tolstov Sergey
Problem fixed with delete *threaded* parameter on Flask, 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

[sqlalchemy] check enums?

2018-01-09 Thread Tolstov Sergey
I create enums with this code *MonthDay = sqlalchemy.types.Enum('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31', name= 'monthday',metadata=Base.metadata)* But i can set it to season.startDate =

Re: [sqlalchemy] How to get ForeignKey from Relationship property

2018-04-11 Thread Tolstov Sergey
Thanks for answer. I dynamicly create classes, their columns, their relationship. Add new works with new_instances, who will load after defintion, and already loaded classes who doesn't contain foreignkeys(for relationships). session.expire(attribute), does not work, because contained foreign key

[sqlalchemy] How to get ForeignKey from Relationship property

2018-04-11 Thread Tolstov Sergey
I use dynamic constructor for class. It works fine for instance who have not foreign keys. But when FK on another instance it cannot load them Example: class left (Base): id = sqlalchemy.Column(UUID, primary_key = True) def __getattr__(self, attribute): if attribute == 'rights':

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-30 Thread Tolstov Sergey
import datetime sl_starttime= datetime.datetime.utcnow() import copy import collections import datetime import enum import json import flask import sqlalchemy import sqlalchemy.ext.declarative import sqlalchemy.orm import sqlalchemy.orm.query import sqlalchemy.sql import sqlalchemy.types import

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-30 Thread Tolstov Sergey
This is may fault, now function found __getattr__, but it cannot find '__sa_instance_state' in self.__dict__ self.__class__.__dict__ it will raise Max recursive eror import datetime sl_starttime= datetime.datetime.utcnow() import copy import collections import datetime import enum import json

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-30 Thread Tolstov Sergey
I'm sorry, not it work. I cannot undestand how work this commands: 1)if (key in self.__dict__ or key in self.__class__.__dict__ or not hasattr(self, '_sa_instance_state') or 'AssociationProxy' in key): Base.__setattr__(self, key, value) 2) self._sa_instance_state.initialize(key) Can you tell

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-29 Thread Tolstov Sergey
Before update it worked. But today i have a exception AttributeError: type object 'Base' has no attribute '__getattr__' -- 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] Re: Using __getattr__ and __setattr__ with sqlalchemy

2018-03-29 Thread Tolstov Sergey
def __getattr__ (self2, key2): if False: pass elif key2 == "attr_new": self2.attr_new = sqlalchemy.Column(UUID, sqlalchemy. ForeignKey(self.RELATED_CLASS.mRID), nullable = True) else: return getattr(self2.__class__, key2)

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-29 Thread Tolstov Sergey
Solved, return getattr(self2.__class__, key2) -- 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

Re: [sqlalchemy] Using __getattr__ and __setattr__ with sqlalchemy

2018-03-30 Thread Tolstov Sergey
import datetime sl_starttime= datetime.datetime.utcnow() import copy import collections import datetime import enum import json import flask import sqlalchemy import sqlalchemy.ext.declarative import sqlalchemy.orm import sqlalchemy.orm.query import sqlalchemy.sql import sqlalchemy.types import

[sqlalchemy] Reload mapper column definition

2018-03-04 Thread Tolstov Sergey
On my project, i use __getattr__ for adding column deifinition to object class Such as: def __getattr__(self,attr): ... my_load_function(...) session.refresh(self) ... return getattr(self,attr) It works, but refresh loses changes on this object. I cannot flush, because

[sqlalchemy] Re: Reload mapper column definition

2018-03-04 Thread Tolstov Sergey
*Addition:* This is a *relationship* -- 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. ---

Re: [sqlalchemy] composite type nested

2018-12-12 Thread Tolstov Sergey
composite(Address.generate, _street_address_name, > _street_address_value, _street_address_town_detail_name, > _street_address_town_detail_value) > > that trick using "Address.generate" isn't documented right now. I > just discovered it :). Another way would

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 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 Tolstov Sergey
composite(Address.generate, _street_address_name, > _street_address_value, _street_address_town_detail_name, > _street_address_town_detail_value) > > that trick using "Address.generate" isn't documented right now. I > just discovered it :). Another way would be make Address.__init__ > know

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

[sqlalchemy] Re: Get sqlalchemy base class object instead of children

2018-12-10 Thread Tolstov Sergey
This query return orm objects. If it will return view as you want, in your session may have two copies of one object ** and * *and they not equals, but need to be equals If you need to print values - You need to create something simular to decorator of data, that return copy of required

[sqlalchemy] composite type nested

2018-12-10 Thread Tolstov Sergey
Can someone have example of this? Example is class TownDetail(object): def __init__(self, name, value): self.name = name self.value = value def __composite_values__(self): return self.name, self.value def __eq__(self, other): return isinstance(other, self.__class__) and\

[sqlalchemy] make reconstructor dynamic

2018-12-17 Thread Tolstov Sergey
Decorator *sqlalchemy.orm.reconstructor* compilated once, when build code. How can i create dynamic content(like *__init__*?) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and

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] __init__ not called for session.query items

2018-12-14 Thread Tolstov Sergey
Is it normal? How i can write methods to loading objects? -- 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

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

2018-12-14 Thread Tolstov Sergey
Did you close and open connection before check on second service? https://www.postgresql.org/docs/10/explicit-locking.html -- 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] Re: __init__ not called for session.query items

2018-12-14 Thread Tolstov Sergey
My bad, answer on here https://docs.sqlalchemy.org/en/latest/orm/constructors.html#constructors-and-object-initialization. Delete this theme, please! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE:

Re: [sqlalchemy] make reconstructor dynamic

2018-12-17 Thread Tolstov Sergey
nope, it anyway called on class created, not on loading понедельник, 17 декабря 2018 г., 13:28:40 UTC+3 пользователь Simon King написал: > > On Mon, Dec 17, 2018 at 9:05 AM Tolstov Sergey > wrote: > > > > Decorator sqlalchemy.orm.reconstructor compilated once, when build

Re: [sqlalchemy] make reconstructor dynamic

2018-12-17 Thread Tolstov Sergey
> > problem not with decorator, > > It is just my fail, i dont know it https://stackoverflow.com/questions/18062443/python-decorator-function-called-at-compile-time -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please

Re: [sqlalchemy] make reconstructor dynamic

2018-12-17 Thread Tolstov Sergey
Now it works, with using class as decorator it not compiled on loading, just when init called понедельник, 17 декабря 2018 г., 15:26:34 UTC+3 пользователь Simon King написал: > > On Mon, Dec 17, 2018 at 11:58 AM Tolstov Sergey > wrote: > >>> > >&g

[sqlalchemy] Redefine class on runtime

2019-03-03 Thread Tolstov Sergey
Hi, for unit tests i need to create class with *Base.metadata.create_all*, and delete table defintion (for tests) On second definition i have a error (already defined) With use *Base.metadata.clear *i get *warning* SAWarning: Reassigning polymorphic association for identity 'testparentclass'

Re: [sqlalchemy] Redefine class on runtime

2019-03-04 Thread Tolstov Sergey
Thanks for answer, can i get only part of classes mappers? Somethink about Myclass.mapper.clear()? -- 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] Custom Handler for "No such polymorphic_identity"

2019-03-12 Thread Tolstov Sergey
Thanks for answer. Problem is too much loading time (~40 seconds) if i use standart declaration. To resolve this, i define classes when they called (write class factory), but on factory i cannot redefine func to get relationship value if return non-main class (such as child) Realization is

Re: [sqlalchemy] Custom Handler for "No such polymorphic_identity"

2019-03-12 Thread Tolstov Sergey
Addition. If i create all possible classes i may get a low perfomance (rel to root class) -- 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: Custom Handler for "No such polymorphic_identity"

2019-03-11 Thread Tolstov Sergey
Another example is cls1 cls1_child(cls1) cls2 cls1_rel = sqlalchemy.rel(cls1, ...) a = session.queyr(cls2) a.cls1_rel - > throw exception if return cls1_child( and it is not loaded before) -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To

[sqlalchemy] Custom Handler for "No such polymorphic_identity"

2019-03-11 Thread Tolstov Sergey
Can i override handler for this error? Example is - > 1) defined only Parent class 2) session.query(Parent) -- > raised Exceptions Resolutions: 1) try_except for all_queries (too much entry points) 2) load all possible classes (low perfomance) How can i override

[sqlalchemy] Re: Custom Handler for "No such polymorphic_identity"

2019-03-11 Thread Tolstov Sergey
Another example is class cls1 (Base) ... class cls1_child(cls1) ... class cls2(Base) cls1_rel = sqlalchemy.rel(cls1, ...) ... a = session.query(cls2) a.cls1_rel - > throw exception if return cls1_child( and it is not loaded before) -- SQLAlchemy - The Python SQL Toolkit and Object

[sqlalchemy] Alembic. Can i pass upgrades and downgrade directly from alembic.command.revision?

2019-04-15 Thread Tolstov Sergey
If i create migrations on GUI (browser), how can i pass upgrades/downgrades? -- 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