[sqlalchemy] update table row immediately after writing
Hello, I am using sqlalchemy with pylons. I write audit log messages to table. I use the orm to map my table to my class. orm.mapper(AuditTable, audit_table) self.engine = create_engine(connect_string) metadata.bind = self.engine metadata.create_all() self.sm = orm.sessionmaker(bind=self.engine, autoflush=True, autocommit=False, expire_on_commit=True) self.session = orm.scoped_session(self.sm) In fact I create the entry with the to be logged information at = AuditTable( info=asdasd, admin=MisterX ... ) Then I add it to my session... self.session.add(at) self.session.flush() self.session.commit() Now I'd like to calculate a signature for each log entry. The primary key id should also be included in the signature. But the id is only available after self.session.flush. So obviously I need to do an update on the table, to rewrite the signature to this table entry. What would be the easiest way to do this? Kind regards Cornelius signature.asc Description: OpenPGP digital signature
Re: [sqlalchemy] update table row immediately after writing
OK, after some more reading and thinking, I think i managed it this way: self.session.add(at) self.session.flush() # At this point at contains the primary key id at.signature = self._sign( at ) self.session.merge(at) self.session.commit() Kind regards Cornelius Am 30.05.2011 15:29, schrieb Cornelius Kölbel: Hello, I am using sqlalchemy with pylons. I write audit log messages to table. I use the orm to map my table to my class. orm.mapper(AuditTable, audit_table) self.engine = create_engine(connect_string) metadata.bind = self.engine metadata.create_all() self.sm = orm.sessionmaker(bind=self.engine, autoflush=True, autocommit=False, expire_on_commit=True) self.session = orm.scoped_session(self.sm) In fact I create the entry with the to be logged information at = AuditTable( info=asdasd, admin=MisterX ... ) Then I add it to my session... self.session.add(at) self.session.flush() self.session.commit() Now I'd like to calculate a signature for each log entry. The primary key id should also be included in the signature. But the id is only available after self.session.flush. So obviously I need to do an update on the table, to rewrite the signature to this table entry. What would be the easiest way to do this? Kind regards Cornelius signature.asc Description: OpenPGP digital signature
[sqlalchemy] Composite Foreign Key with ondelete='CASCADE' does not work on mysql
I have a composite Primary key in a table and a relative Foreign Key in another as: sensors = Table('sensors', metadata, Column('id_cu', Integer, ForeignKey('ctrl_units.id', ondelete='CASCADE'), primary_key=True, autoincrement=False), Column('id_meas', Integer, primary_key=True, autoincrement=False), ... ) view_opts = Table('view_opts', metadata, Column('id', Integer, primary_key=True), Column('id_view', Integer, ForeignKey('views.id', ondelete='CASCADE'), nullable=False), Column('id_cu', Integer, ForeignKey('ctrl_units.id'), nullable=False), Column('id_meas', Integer, nullable=False), ForeignKeyConstraint(('id_cu', 'id_meas'), ('sensors.id_cu', 'sensors.id_meas'), ondelete='CASCADE'), ... ) mapped like this: orm.mapper(Sensor, sensors, properties={ 'view_opts': orm.relationship(ViewOpt, backref='sensor', cascade='all, delete-orphan', passive_deletes=True, single_parent=True) }) Now when I delete a row from sensor relative view_opt rows are not removed. I can't understand if this depends on DDL, it's a MySQL bug, something sqlalchemy related or whatever. I know I set `passive_deletes=True`to get MySQL ONDELETE CASCADE take care of it more and more quickly. Any help appreciated, thanks for your support neurino -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Joining against a subquery and polymorphic contains_eager population
This is my first post here, I've been learning about the query api and I've got three related questions: 1. Suppose I have a User model and UserThing which is loaded into the User.things collection, UserThing is polymorphic via joined table inheritance. I'd like to do something like this: subq = s.query(UserThing).with_polymorphic('*').with_labels().subquery() users_with_eagerly_loaded_things = s.query(User).join(subq, User.things).options(contains_eager(User.things, alias=subq)).all() This works, the query appears to be rendered correctly, and the base-class attributes of the collection are populated eagerly and work fine, but the polymorphic attributes (attributes unique to the inherited classes) of the collections aren't populated, so when I do: print users_with_eagerly_loaded_things[0].some_polylmorphic_attribute Sqlalchemy issues more sql to fetch those attributes even though they were already fetched in the subquery and should have been populated by the contains_eager option. It is as if the subquery only queried the table for the base class, even though I have verified that when I add the with_polymorphic('*') it joins against all the inherited tables as well. What am I doing wrong? In addition to doing this via a query, is there an attribute I can specify on a collection to have that collection always use a polymorphic eager load? 2. On a similar note, suppose if in that join I want to specify a join condition manually, how do I refer to the alias of the subquery -- I cant seem to figure out the syntax of that, e.g. s.query(User).join(subq, subq.user_id == User.id) #(but subq.user_id gives me an error) 3. One final question, suppose I want an explicit join kind of like this that returns tuples of (User, UserThing): s.query(User, UserThing).join(subq).all() but the above will give me a cartesian product of Users and UserThings, because sqlalchemy doesn't know that the subquery is specifying UserThings. What I really want is results returned as the subq joined to the user in a tuple, this works s.query(User, subq).join(subq) but doesn't return results in the form I want. I get all of the fields of the subquery individually rather than nicely being populated into a UserThing object, e.g. results look like (User, userthing_id, userthing_name, userthing_data). How do I get this query to return results that look like (User,UserThing) if the UserThings are fetched via a subquery? Finally, I also just wanted to say how awesome I find your software -- I just started using sqlalchemy about a month ago and every time I need to do something I am amazed by how sqlalchemy handles it and how much easier it makes my life as well as the extensive support community which exists. Thanks!! Best, Jesse Cohen -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] update table row immediately after writing
2011/5/30 Cornelius Kölbel cornelius.koel...@lsexperts.de OK, after some more reading and thinking, I think i managed it this way: self.session.add(at) self.session.flush() # At this point at contains the primary key id at.signature = self._sign( at ) self.session.merge(at) This merge should not be needed, In this case with the session configured as you have it the update is flushed to the database prior to the commit. Try a little test with echo=True on the engine and you will see it. self.session.commit() Kind regards Cornelius -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Vs: Composite Foreign Key with ondelete='CASCADE' does not work on mysql
It's not clear from your code, but are you using InnoDB or MyISAM? You need to be using InnoDB for foreign keys to work properly. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Re: Composite Foreign Key with ondelete='CASCADE' does not work on mysql
You need to use InnoDB engine, so you tables definitions 'll look like: sensors = Table('sensors', metadata, ... mysql_engine='InnoDB' ) view_opts = Table('view_opts', metadata, ... mysql_engine='InnoDB' ) On 30 Maj, 17:38, neurino neur...@gmail.com wrote: I have a composite Primary key in a table and a relative Foreign Key in another as: sensors = Table('sensors', metadata, Column('id_cu', Integer, ForeignKey('ctrl_units.id', ondelete='CASCADE'), primary_key=True, autoincrement=False), Column('id_meas', Integer, primary_key=True, autoincrement=False), ... ) view_opts = Table('view_opts', metadata, Column('id', Integer, primary_key=True), Column('id_view', Integer, ForeignKey('views.id', ondelete='CASCADE'), nullable=False), Column('id_cu', Integer, ForeignKey('ctrl_units.id'), nullable=False), Column('id_meas', Integer, nullable=False), ForeignKeyConstraint(('id_cu', 'id_meas'), ('sensors.id_cu', 'sensors.id_meas'), ondelete='CASCADE'), ... ) mapped like this: orm.mapper(Sensor, sensors, properties={ 'view_opts': orm.relationship(ViewOpt, backref='sensor', cascade='all, delete-orphan', passive_deletes=True, single_parent=True) }) Now when I delete a row from sensor relative view_opt rows are not removed. I can't understand if this depends on DDL, it's a MySQL bug, something sqlalchemy related or whatever. I know I set `passive_deletes=True`to get MySQL ONDELETE CASCADE take care of it more and more quickly. Any help appreciated, thanks for your support neurino -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Mapping rows as attributes
Hello, I am trying to map a legacy schema. There are a few tables that I cannot figure out how to map. Basically the rows are key-value pairs that should really be columns in the table (see code examples below). The rows of the ideal table would match the distinct values in the physical table's first column (username), which would be natural to use as the primary key. I would like to know what needs to be done in order to make this kind of mapping work, so that object add and changes to session would still do the right thing when flush()ed etc. So far I haven't been able to figure out exactly how that could be done from the docs, and I am not familiar enough with the inner workings of SQLAlchemy. Any advice would be greatly appreciated. # Real table. Contains rows like: # 'jsmith', 'realname', 'John Smith' # 'jsmith', 'address', 'Park Avenue' # 'jsmith', 'phone', '555-9876' # 'tkelly', 'realname', 'Tim Kelly' # etc. users_table = Table('users', metadata, Column('username', Unicode, primary_key=True), Column('attr', Unicode, primary_key=True), Column('val', Unicode) ) # Ideal - what I'd like the mapping to act like users_table = Table('users', metadata, Column('username', Unicode), Column('realname', Unicode), Column('address', Unicode) Column('phone', Unicode) # etc... ) Thanks, -- Teemu Yli-Elsilä -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Mapping rows as attributes
This is called a vertical table format and we have a few recipes that illustrate this, including the examples introduced at http://www.sqlalchemy.org/docs/orm/examples.html#vertical-attribute-mapping as well as http://www.sqlalchemy.org/trac/wiki/UsageRecipes/VersionedMap .The basic premise is to map a class to users_table that represents just a key/value pair, then to use them to construct a dictionary. Your specific layout is a little tricky in that there's no parent table - so queries for a specific username will need a little bit of a facade (like, get_user(username) would query a set of UserKeyValue objects, make a dict-like interface out of them, return it - the dict would then alter/delete/create UserKeyValue objects based on __setitem__, __delitem__, etc.). Another option is if you had only a limited set of attr, you could make a database view which represents a row for a specific username - i.e. select u1a.val as u1, u2a.val as u2, u3a.val as u3 from users as u1a join users as u2a on u1a.username=u2a.username join users as u3a on u2a.username=u3a.username where u1a.attr='attr1' and u2a.attr='attr2' and u3a.attr='attr3'.Then map to that. The join approach doesn't really scale to more than a small handful of attributes though. On May 30, 2011, at 2:56 PM, Teemu Yli-Elsilä wrote: Hello, I am trying to map a legacy schema. There are a few tables that I cannot figure out how to map. Basically the rows are key-value pairs that should really be columns in the table (see code examples below). The rows of the ideal table would match the distinct values in the physical table's first column (username), which would be natural to use as the primary key. I would like to know what needs to be done in order to make this kind of mapping work, so that object add and changes to session would still do the right thing when flush()ed etc. So far I haven't been able to figure out exactly how that could be done from the docs, and I am not familiar enough with the inner workings of SQLAlchemy. Any advice would be greatly appreciated. # Real table. Contains rows like: # 'jsmith', 'realname', 'John Smith' # 'jsmith', 'address', 'Park Avenue' # 'jsmith', 'phone', '555-9876' # 'tkelly', 'realname', 'Tim Kelly' # etc. users_table = Table('users', metadata, Column('username', Unicode, primary_key=True), Column('attr', Unicode, primary_key=True), Column('val', Unicode) ) # Ideal - what I'd like the mapping to act like users_table = Table('users', metadata, Column('username', Unicode), Column('realname', Unicode), Column('address', Unicode) Column('phone', Unicode) # etc... ) Thanks, -- Teemu Yli-Elsilä -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Re: Composite Foreign Key with ondelete='CASCADE' does not work on mysql
Sorry if I did not specified, yes it's InnoDB. So do I HAVE to put `mysql_engine='InnoDB'` in any Table using ondelete cascade? Is there a link to docs with some info on it? Thanks for your support On May 30, 7:04 pm, virhilo virh...@gmail.com wrote: You need to use InnoDB engine, so you tables definitions 'll look like: sensors = Table('sensors', metadata, ... mysql_engine='InnoDB' ) view_opts = Table('view_opts', metadata, ... mysql_engine='InnoDB' ) On 30 Maj, 17:38, neurino neur...@gmail.com wrote: I have a composite Primary key in a table and a relative Foreign Key in another as: sensors = Table('sensors', metadata, Column('id_cu', Integer, ForeignKey('ctrl_units.id', ondelete='CASCADE'), primary_key=True, autoincrement=False), Column('id_meas', Integer, primary_key=True, autoincrement=False), ... ) view_opts = Table('view_opts', metadata, Column('id', Integer, primary_key=True), Column('id_view', Integer, ForeignKey('views.id', ondelete='CASCADE'), nullable=False), Column('id_cu', Integer, ForeignKey('ctrl_units.id'), nullable=False), Column('id_meas', Integer, nullable=False), ForeignKeyConstraint(('id_cu', 'id_meas'), ('sensors.id_cu', 'sensors.id_meas'), ondelete='CASCADE'), ... ) mapped like this: orm.mapper(Sensor, sensors, properties={ 'view_opts': orm.relationship(ViewOpt, backref='sensor', cascade='all, delete-orphan', passive_deletes=True, single_parent=True) }) Now when I delete a row from sensor relative view_opt rows are not removed. I can't understand if this depends on DDL, it's a MySQL bug, something sqlalchemy related or whatever. I know I set `passive_deletes=True`to get MySQL ONDELETE CASCADE take care of it more and more quickly. Any help appreciated, thanks for your support neurino -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Re: Composite Foreign Key with ondelete='CASCADE' does not work on mysql
The table has to be created with both InnoDB as well as ON DELETE CASCADE, on the MySQL side, meaning these both must be present in the CREATE TABLE statement used to create the tables in the database. On the SQLAlchemy side, these options don't have any meaning outside the emission of the CREATE statement. On May 30, 2011, at 6:10 PM, neurino wrote: Sorry if I did not specified, yes it's InnoDB. So do I HAVE to put `mysql_engine='InnoDB'` in any Table using ondelete cascade? Is there a link to docs with some info on it? Thanks for your support On May 30, 7:04 pm, virhilo virh...@gmail.com wrote: You need to use InnoDB engine, so you tables definitions 'll look like: sensors = Table('sensors', metadata, ... mysql_engine='InnoDB' ) view_opts = Table('view_opts', metadata, ... mysql_engine='InnoDB' ) On 30 Maj, 17:38, neurino neur...@gmail.com wrote: I have a composite Primary key in a table and a relative Foreign Key in another as: sensors = Table('sensors', metadata, Column('id_cu', Integer, ForeignKey('ctrl_units.id', ondelete='CASCADE'), primary_key=True, autoincrement=False), Column('id_meas', Integer, primary_key=True, autoincrement=False), ... ) view_opts = Table('view_opts', metadata, Column('id', Integer, primary_key=True), Column('id_view', Integer, ForeignKey('views.id', ondelete='CASCADE'), nullable=False), Column('id_cu', Integer, ForeignKey('ctrl_units.id'), nullable=False), Column('id_meas', Integer, nullable=False), ForeignKeyConstraint(('id_cu', 'id_meas'), ('sensors.id_cu', 'sensors.id_meas'), ondelete='CASCADE'), ... ) mapped like this: orm.mapper(Sensor, sensors, properties={ 'view_opts': orm.relationship(ViewOpt, backref='sensor', cascade='all, delete-orphan', passive_deletes=True, single_parent=True) }) Now when I delete a row from sensor relative view_opt rows are not removed. I can't understand if this depends on DDL, it's a MySQL bug, something sqlalchemy related or whatever. I know I set `passive_deletes=True`to get MySQL ONDELETE CASCADE take care of it more and more quickly. Any help appreciated, thanks for your support neurino -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Problem accessing sqlite records w primary keys imported from csv file
Hello, I have an issue, not sure if it is a bug or I am just screwing some things up. Anyway: I am using pyramid with a sqlite db in develop mode (still not in production). I then imported some data from csv into a table which includes a primary key. (that is: primary key id values included in the csv and was imported in the primary key auto increment column) When querying the data, sqalchemy throws an error. AttributeError: 'NoneType' object has no attribute 'groups' It seems the 'row' variable is None. The catch is: this error does not appear when trying to *only* query records created via sqlalchemy via the web interface before or after said import. However, when any query result includes *any* of the records that was originally added via the import and not via sqlalchemy ... this error is thrown. It is as if sqlalchemy cannot read/fetch the entered primary key values 'manually' set via the import. I am not sure if I am doing the right approach for the import, but I would appreciate any advice, and if you think it is a bug, then I will then submit it in the correct place for that. Cheers, Ahmed Here is the sqlalchemy error: File '/home/ahmed/dev/pyrenv/gess/gess/models/__init__.py', line 97 in query_byID return DBSession.query(model).filter_by(id=id).one() File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1646 in one ret = list(self) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1798 in instances rows = [process[0](row, None) for row in fetch] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2281 in _instance populate_state(state, dict_, row, isnew, only_load_props) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2159 in populate_state populator(state, dict_, row) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/strategies.py', line 130 in new_execute dict_[key] = row[col] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 2023 in __getitem__ return processor(self._row[index]) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/processors.py', line 27 in process return type_(*map(int, rmatch(value).groups(0))) AttributeError: 'NoneType' object has no attribute 'groups' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Problem accessing sqlite records w primary keys imported from csv file
This is a malformed date value. SQLite has no date type so SQLA must parse it. It assumes its only parsing strings that it created. If you're artificially generating strings to be used with DateTime, make sure you put dates in the format as follows: 2011-03-15 12:05:57.10558 On May 30, 2011, at 11:11 PM, Ahmed wrote: Hello, I have an issue, not sure if it is a bug or I am just screwing some things up. Anyway: I am using pyramid with a sqlite db in develop mode (still not in production). I then imported some data from csv into a table which includes a primary key. (that is: primary key id values included in the csv and was imported in the primary key auto increment column) When querying the data, sqalchemy throws an error. AttributeError: 'NoneType' object has no attribute 'groups' It seems the 'row' variable is None. The catch is: this error does not appear when trying to *only* query records created via sqlalchemy via the web interface before or after said import. However, when any query result includes *any* of the records that was originally added via the import and not via sqlalchemy ... this error is thrown. It is as if sqlalchemy cannot read/fetch the entered primary key values 'manually' set via the import. I am not sure if I am doing the right approach for the import, but I would appreciate any advice, and if you think it is a bug, then I will then submit it in the correct place for that. Cheers, Ahmed Here is the sqlalchemy error: File '/home/ahmed/dev/pyrenv/gess/gess/models/__init__.py', line 97 in query_byID return DBSession.query(model).filter_by(id=id).one() File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1646 in one ret = list(self) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1798 in instances rows = [process[0](row, None) for row in fetch] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2281 in _instance populate_state(state, dict_, row, isnew, only_load_props) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2159 in populate_state populator(state, dict_, row) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/strategies.py', line 130 in new_execute dict_[key] = row[col] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 2023 in __getitem__ return processor(self._row[index]) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/processors.py', line 27 in process return type_(*map(int, rmatch(value).groups(0))) AttributeError: 'NoneType' object has no attribute 'groups' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.
[sqlalchemy] Re: Problem accessing sqlite records w primary keys imported from csv file
I just found a similar error here from FEB 2011. http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg22861.html And similar to what happened in that thread, when I deleted the date column, the error disappeared!! Perhaps it has something to do with the formatting of the dates in sqlite, because when I enter the data through the web interface forms (I use formalchemy) it works fine. I wonder why it would mess up querying though! I will have to look into this. Cheers, Ahmed On Tue, May 31, 2011 at 12:41 PM, Ahmed ahmedba...@gmail.com wrote: Hello, I have an issue, not sure if it is a bug or I am just screwing some things up. Anyway: I am using pyramid with a sqlite db in develop mode (still not in production). I then imported some data from csv into a table which includes a primary key. (that is: primary key id values included in the csv and was imported in the primary key auto increment column) When querying the data, sqalchemy throws an error. AttributeError: 'NoneType' object has no attribute 'groups' It seems the 'row' variable is None. The catch is: this error does not appear when trying to *only* query records created via sqlalchemy via the web interface before or after said import. However, when any query result includes *any* of the records that was originally added via the import and not via sqlalchemy ... this error is thrown. It is as if sqlalchemy cannot read/fetch the entered primary key values 'manually' set via the import. I am not sure if I am doing the right approach for the import, but I would appreciate any advice, and if you think it is a bug, then I will then submit it in the correct place for that. Cheers, Ahmed Here is the sqlalchemy error: File '/home/ahmed/dev/pyrenv/gess/gess/models/__init__.py', line 97 in query_byID return DBSession.query(model).filter_by(id=id).one() File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1646 in one ret = list(self) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/query.py', line 1798 in instances rows = [process[0](row, None) for row in fetch] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2281 in _instance populate_state(state, dict_, row, isnew, only_load_props) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/mapper.py', line 2159 in populate_state populator(state, dict_, row) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/strategies.py', line 130 in new_execute dict_[key] = row[col] File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/engine/base.py', line 2023 in __getitem__ return processor(self._row[index]) File '/home/ahmed/dev/pyrenv/lib/python2.6/site-packages/ SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/processors.py', line 27 in process return type_(*map(int, rmatch(value).groups(0))) AttributeError: 'NoneType' object has no attribute 'groups' -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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.