Re: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState'
jo wrote: Hi all, I cannot find anymore the attribute _state : if (not cls._state or not cls._state.get('original') or (cls._state['original'].data.get(k) != data.get(k: Could someone please help me? thank you j To explain better my problem, in version 0.3 my models have the attribute _state where I find the class 'sqlalchemy.orm.attributes.CommittedState' (Pdb) self._state {'original': CommittedState: {'anagrafica_dato_fiscale': u'02241850367/02241850367', 'anagrafica_id_operatore': 1, 'anagrafica_cap': None, 'anagrafica_telefono': None, 'anagrafica_email': None, 'anagrafica_nome': u'AZ.USL MODENA distr. PAVULLO', 'anagrafica_cod_nazione_nascita': None, 'anagrafica_localita': None, 'anagrafica_tipo': u'S', 'anagrafica_cod_cittadinanza': None, 'anagrafica_tipo_persona': u'S', 'anagrafica_ts_ultima_modifica': datetime.datetime(2010, 3, 3, 16, 4, 22, 50891, tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0xc13488c), 'anagrafica_id': 8, 'anagrafica_data_nascita': None, 'anagrafica_id_comune_nascita': None, 'anagrafica_id_comune': 15090, 'anagrafica_cod_professione': None, 'anagrafica_indirizzo': u'?', 'anagrafica_cod_titolo_studio': None}, 'modified': False} I can't find this attribute anymore on version 0.6 j -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
RE: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState'
-Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of jose soares Sent: 16 April 2010 11:03 To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState' jo wrote: Hi all, I cannot find anymore the attribute _state : if (not cls._state or not cls._state.get('original') or (cls._state['original'].data.get(k) != data.get(k: Could someone please help me? thank you j To explain better my problem, in version 0.3 my models have the attribute _state where I find the class 'sqlalchemy.orm.attributes.CommittedState' (Pdb) self._state {'original': CommittedState: {'anagrafica_dato_fiscale': u'02241850367/02241850367', 'anagrafica_id_operatore': 1, 'anagrafica_cap': None, 'anagrafica_telefono': None, 'anagrafica_email': None, 'anagrafica_nome': u'AZ.USL MODENA distr. PAVULLO', 'anagrafica_cod_nazione_nascita': None, 'anagrafica_localita': None, 'anagrafica_tipo': u'S', 'anagrafica_cod_cittadinanza': None, 'anagrafica_tipo_persona': u'S', 'anagrafica_ts_ultima_modifica': datetime.datetime(2010, 3, 3, 16, 4, 22, 50891, tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0xc13488c), 'anagrafica_id': 8, 'anagrafica_data_nascita': None, 'anagrafica_id_comune_nascita': None, 'anagrafica_id_comune': 15090, 'anagrafica_cod_professione': None, 'anagrafica_indirizzo': u'?', 'anagrafica_cod_titolo_studio': None}, 'modified': False} I can't find this attribute anymore on version 0.6 j I haven't used this, so I don't know if this helps, but you may be interested in a couple of the functions described at http://www.sqlalchemy.org/docs/reference/orm/mapping.html#attribute-util ities In particular, either the instance_state() function or the get_history() function might be useful. I'm not sure there's much documentation for either the History class or the InstanceState class so you'll have to read the code in sqlalchemy.orm.state and sqlalchemy.orm.attributes Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState'
King Simon-NFHD78 wrote: -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalch...@googlegroups.com] On Behalf Of jose soares Sent: 16 April 2010 11:03 To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState' jo wrote: Hi all, I cannot find anymore the attribute _state : if (not cls._state or not cls._state.get('original') or (cls._state['original'].data.get(k) != data.get(k: Could someone please help me? thank you j To explain better my problem, in version 0.3 my models have the attribute _state where I find the class 'sqlalchemy.orm.attributes.CommittedState' (Pdb) self._state {'original': CommittedState: {'anagrafica_dato_fiscale': u'02241850367/02241850367', 'anagrafica_id_operatore': 1, 'anagrafica_cap': None, 'anagrafica_telefono': None, 'anagrafica_email': None, 'anagrafica_nome': u'AZ.USL MODENA distr. PAVULLO', 'anagrafica_cod_nazione_nascita': None, 'anagrafica_localita': None, 'anagrafica_tipo': u'S', 'anagrafica_cod_cittadinanza': None, 'anagrafica_tipo_persona': u'S', 'anagrafica_ts_ultima_modifica': datetime.datetime(2010, 3, 3, 16, 4, 22, 50891, tzinfo=psycopg2.tz.FixedOffsetTimezone object at 0xc13488c), 'anagrafica_id': 8, 'anagrafica_data_nascita': None, 'anagrafica_id_comune_nascita': None, 'anagrafica_id_comune': 15090, 'anagrafica_cod_professione': None, 'anagrafica_indirizzo': u'?', 'anagrafica_cod_titolo_studio': None}, 'modified': False} I can't find this attribute anymore on version 0.6 j I haven't used this, so I don't know if this helps, but you may be interested in a couple of the functions described at http://www.sqlalchemy.org/docs/reference/orm/mapping.html#attribute-util ities In particular, either the instance_state() function or the get_history() function might be useful. I'm not sure there's much documentation for either the History class or the InstanceState class so you'll have to read the code in sqlalchemy.orm.state and sqlalchemy.orm.attributes Hope that helps, Simon Thank you for replay my question, Simon, but I can't find the 'original' state there. j -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] cls._state / cls._state.get('original') class 'sqlalchemy.orm.attributes.CommittedState'
Yes, it works, :-) Thank you Simon, j King Simon-NFHD78 wrote: Jo wrote: Thank you for replay my question, Simon, but I can't find the 'original' state there. j Here's an example that shows the results of the get_history function: # import sqlalchemy as sa import sqlalchemy.orm as saorm import sqlalchemy.ext.declarative as decl from sqlalchemy.orm.attributes import get_history Base = decl.declarative_base() class User(Base): __tablename__ = 'user' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String) def display_history(prefix, obj, attr): history = get_history(obj, attr) print '%16s: added=%r, unchanged=%r, deleted=%r' % (prefix, history.added, history.unchanged, history.deleted) engine = sa.create_engine('sqlite://') Base.metadata.create_all(bind=engine) Session = saorm.sessionmaker(bind=engine) sess = Session() u = User(name='jose') sess.add(u) display_history('Before commit', u, 'name') sess.commit() u = sess.query(User).get(1) display_history('After load', u, 'name') u.name = 'simon' display_history('Modified once', u, 'name') u.name = 'sqlalchemy rules' display_history('Modified twice', u, 'name') sess.commit() display_history('After commit', u, 'name') # And here are the results: Before commit: added=['jose'], unchanged=(), deleted=() After load: added=(), unchanged=[u'jose'], deleted=() Modified once: added=['simon'], unchanged=(), deleted=[u'jose'] Modified twice: added=['sqlalchemy rules'], unchanged=(), deleted=[u'jose'] After commit: added=(), unchanged=(), deleted=() So when you change a scalar attribute, the old value appears in the 'deleted' list, and the new value in the 'added' list. I'm not sure exactly when the unchanged attribute is used - I would guess it normally contains the value loaded from the database as long as it hasn't been modified. I expect it is empty in the 'After commit' line because the instance has been expired. Hope that helps, Simon -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.