Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-03-01 Thread Ahmed
>
> yes so, SQLAlchemy 2.0's approach is frankly at odds with the spirit of
> Flask-SQLAlchemy.The Query and "dynamic" loaders are staying around
> largely so that Flask can come on board, however the patterns in F-S are
> pretty much the ones I want to get away from.


2.0's spirit is one where the act of creating a SELECT statement is a
> standalone thing that is separate from being attached to any specific class
> (really all of SQLAlchemy was like this, but F-S has everyone doing the
> Model.query thing that I've always found to be more misleading than
> helpful), but SELECT statements are now also disconnected from any kind of
> "engine" or "Session" when constructed.



as for with_parent(), with_parent is what the dynamic loader actually uses
> to create the query.  so this is a matter of code organization.
> F-S would have you say:
>


user = User.query.filter_by(name='name').first()
> address = user.addresses.filter_by(email='email').first()
>


noting above, there's no "Session" anywhere.  where is it?   Here's a
> Hacker News comment lamenting the real world implications of this:
> https://news.ycombinator.com/item?id=26183936
>


SQLAlchemy 2.0 would have you say instead:
>


with Session(engine) as session:
> user = session.execute(
>   select(User).filter_by(name='name')
> ).scalars().first()
>
>address = session.execute(
>select(Address).where(with_parent(user,
> Address.user)).filter_by(email='email')
>).scalars().first()
>


Noting above, a web framework integration may still wish to provide the
> "session" to data-oriented methods and manage its scope, but IMO it should
> be an explicit object passed around.  The database connection / transaction
> shouldn't be made to appear to be inside the ORM model object, since that's
> not what's actually going on.


The newer design indeed provides a clearer view of the session.

If you look at any commentary anywhere about SQLAlchemy, the top complaints
> are:


> 1. too magical, too implicit


> 2. what's wrong with just writing SQL?


> SQLAlchemy 2.0 seeks to streamline the act of ORMing such that the user
> *is* writing SQL, they're running it into an execute() method, and they are
> managing the scope of connectivity and transactions in an obvious way.
> People don't necessarily want bloat and verbosity but they do want to see
> explicitness when the computer is being told to do something, especially
> running a SQL query.  We're trying to hit that balance as closely as
> possible.


> The above style also has in mind compatibility with asyncio, which we now
> support.  With asyncio, it's very important that the boundary where IO
> occurs is very obvious.  Hence the Session.execute() method now becomes the
> place where users have to "yield".  With the older Query interface, the
> "yields" would be all over the place and kind of arbirary, since some Query
> methods decide to execute at one point or another.


> Flask-SQLAlchemy therefore has to decide where it wants to go with this
> direction, and there are options, including sticking with the legacy query
> / dynamic loader, perhaps vendoring a new interface that behaves in the
> flask-sqlalchemy style but uses 2.0-style patterns under the hood, or it
> can go along with the 2.0 model for future releases.   From
> SQLAlchemy's point of view, the Query was always not well thought out and
> was inconsistent with how Core worked, and I've wanted for years to resolve
> that problem.


I'm not authorized to talk on behalf of F-S but IMO, these options could be
milestones applied in parallel toward migration to 2.0. However, a question
arises here, that you might have already seen, which is: given the major
leap in how SQLAlchemy 2.0 is designed, is it better to think of rebuilding
medium+ projects for 2.0 while maintaining existing codebases for 1.3? In
other words, how much will 2.0 be backward compatible with 1.3?

 A.

On Fri, Feb 26, 2021, 5:18 PM Mike Bayer  wrote:

>
>
> On Fri, Feb 26, 2021, at 8:04 AM, Ahmed wrote:
>
> Hi Mike - Thank you for your insights. Actually, this is part of upgrading
> Flask-SQLAlchemy library dependency to 1.4.0b3 and eventually 2.0. The
> snippet above is extracted from a test case that didn't pass against
> 1.4.0b3.
>
> I've checked sqlalchemy.orm.with_parent
> <https://docs.sqlalchemy.org/en/14/orm/query.html?highlight=with_parent#sqlalchemy.orm.with_parent>
>  (Python
> function, in Query API) documentation entry, however, it's not clear to me
> how with_parent construct can fit in the implementation instead of Query.
> I guess it would require a major change in how the library
> (Flask-SQLAlchemy) is currently designed as it fun

Re: [sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-26 Thread Ahmed
Hi Mike - Thank you for your insights. Actually, this is part of upgrading 
Flask-SQLAlchemy library dependency to 1.4.0b3 and eventually 2.0. The 
snippet above is extracted from a test case that didn't pass against 
1.4.0b3.

I've checked sqlalchemy.orm.with_parent 
<https://docs.sqlalchemy.org/en/14/orm/query.html?highlight=with_parent#sqlalchemy.orm.with_parent>
 (Python 
function, in Query API) documentation entry, however, it's not clear to me 
how with_parent construct can fit in the implementation instead of Query. I 
guess it would require a major change in how the library (Flask-SQLAlchemy) 
is currently designed as it functionally extends sqlalchemy.orm.Query and 
pass the extended class to relationship and other constructs as well.
On Thursday, February 25, 2021 at 2:21:43 PM UTC-8 Mike Bayer wrote:

> this will be fixed in https://github.com/sqlalchemy/sqlalchemy/issues/5981  
> where I've reverted entirely some changes to AppenderQuery that made it 
> work more in 2.0 style.  As Query is going to be present in 2.0, "dynamic" 
> relationships will remain also as legacy.   They are superseded by explicit 
> use of the with_parent() filtering construct.
>
>
>
> On Thu, Feb 25, 2021, at 3:25 PM, Ahmed wrote:
>
> Hello,
>
> It seems that SQLAlchemy 1.4.0b3 ignores relationship()  query_class 
> parameter. Here's the snippet that works with 1.3 but doesn't with 1.4:
>
> class Parent(db.Model):
> __tablename__ = "todo"
> id = db.Column(db.Integer, primary_key=True)
> # ... Column mappings
> children = db.relationship("Child", 
> backref="todo", query_class=DerivedQuery, lazy="dynamic")
>
> class Child(db.Model):
> __tablename__ = "todo"
> # ... Column mappings
> parent_id = db.Column(db.Integer, db.ForeignKey("todo.id"))
>
> assert isinstance(p.children, DerivedQuery)
>
> In 1.4, children attribute is always an instance of AppenderQuery 
> regardless of the query_class value. I might have missed something above 
> though.
>
>
>
> -- 
> 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 this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/4454277c-b3a1-484e-b0e5-aef3e72eeb01n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/4454277c-b3a1-484e-b0e5-aef3e72eeb01n%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>

-- 
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 this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/087934f8-d7fb-4062-8b2a-9d623a2e7941n%40googlegroups.com.


[sqlalchemy] relationship query_class in SQLAlchemy 1.4.0b3

2021-02-25 Thread Ahmed
Hello,

It seems that SQLAlchemy 1.4.0b3 ignores relationship()  query_class 
parameter. Here's the snippet that works with 1.3 but doesn't with 1.4:

class Parent(db.Model):
__tablename__ = "todo"
id = db.Column(db.Integer, primary_key=True)
# ... Column mappings
children = db.relationship("Child", 
backref="todo", query_class=DerivedQuery, lazy="dynamic")

class Child(db.Model):
__tablename__ = "todo"
# ... Column mappings
parent_id = db.Column(db.Integer, db.ForeignKey("todo.id"))

assert isinstance(p.children, DerivedQuery)

In 1.4, children attribute is always an instance of AppenderQuery 
regardless of the query_class value. I might have missed something above 
though.


-- 
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 this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/4454277c-b3a1-484e-b0e5-aef3e72eeb01n%40googlegroups.com.


Re: [sqlalchemy] SQLAlchemy Memory Leak

2020-03-04 Thread Ahmed Cheikh
I tried the obj.expire(obj) and it did unfortunately not change anything. I 
still have accumulating used memory for whatever reason. When I did profile 
the code I saw that sometime engine objects use memory and sometimes 
session. 
Do any of  you guys have any other suggestions

Le jeudi 27 février 2020 05:17:08 UTC+1, João Miguel Neves a écrit :
>
> Hi,
>
> When you go through the objects, do you remove them from the session with 
> session.expire(obj)?
>
> Hope this helps,
> João
>
> On Wed, 26 Feb 2020 at 17:09, Ahmed Cheikh  > wrote:
>
>> Hello Everybody, 
>>
>> I used SQLAlchemy in one of my projects. And in this project, I loop over 
>> many objects. I use for each object the same engine and session object to 
>> query from my database. What I noticed is that for each loop, there is an 
>> increase in the memory usage. 
>> I checked all the other reasons that could potientially lead to a memory 
>> leak and thee was none. So I was wondering if any of you faced such a 
>> problem? And if so did you find any solution
>>
>> PS: I tried closing all my sessions after each iteration, delete session 
>> object and then garbage collect it, dispose engine and even used the 
>> recently added sqlalchemy.orm.session.close_all_sessions()
>>
>> Thx for your help.
>>
>> -- 
>> 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 this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sqlal...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/sqlalchemy/26f16790-685c-42aa-9c36-27970c838ffe%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/sqlalchemy/26f16790-685c-42aa-9c36-27970c838ffe%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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 this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/18f34cfb-9d80-4747-9e4c-7e538f813344%40googlegroups.com.


[sqlalchemy] SQLAlchemy Memory Leak

2020-02-26 Thread Ahmed Cheikh
Hello Everybody, 

I used SQLAlchemy in one of my projects. And in this project, I loop over 
many objects. I use for each object the same engine and session object to 
query from my database. What I noticed is that for each loop, there is an 
increase in the memory usage. 
I checked all the other reasons that could potientially lead to a memory 
leak and thee was none. So I was wondering if any of you faced such a 
problem? And if so did you find any solution

PS: I tried closing all my sessions after each iteration, delete session 
object and then garbage collect it, dispose engine and even used the 
recently added sqlalchemy.orm.session.close_all_sessions()

Thx for your help.

-- 
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 this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/26f16790-685c-42aa-9c36-27970c838ffe%40googlegroups.com.


[sqlalchemy] Finding the most recent raw (sqlalchemy core)

2014-12-24 Thread Ahmed Ezzeldin
products_attribute = Table(Column('id', INTEGER()), Column('product_id', 
INTEGER(), ForeignKey(u'product.id')), Column('name', TEXT()), 
Column('value', TEXT()), Column('timestamp', TIMESTAMP())


 product_id   name   value  timestamp
   23   'Price' 1578.0   
datetime.datetime(2014, 10, 24, 11, 16, 47, 309000)
   23   'Price' 1838.0   
datetime.datetime(2014, 11, 9, 10, 48, 18, 533000)
   23   'Price' 1840.0   
datetime.datetime(2014, 10, 5, 2, 55, 34, 31000)
   23   'Price' 1599.0   
 datetime.datetime(2014, 9, 11, 15, 1, 17, 595000)
   23   'Brand' hp   
  datetime.datetime(2014, 9, 11, 15, 1, 17, 596000)
   23   'Brand' hp   
  datetime.datetime(2014, 9, 12, 12, 2, 12, 523200)



How can I get the most recent row from multiple names and values with the 
same name ??

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: Changing the declarative base of a class and re-mapping

2013-07-13 Thread Ahmed
It seems that I have found a solution. After digging in sqlalchemy code, it 
seems that the _configure_property mapper function would do the trick.

so ...

newprop = RelationshipProperty(newtargetmodel, **rel_kwargs)
newparentmodel.__mapper__._configure_property(oldprop.key, newprop)

so what I did above was to construct a new RelationshipProperty (copying 
all the key word arguments from the old property) and then configure it 
onto the new model (which inherits from the old one).

Before this step I also disposed of the old model mapper using 
mapper.dispose() and remapped using mapper() but without specifying the 
relationships in the mapper 'properties', this gave me the same classes 
with only the columns and without the relationship properties, which I then 
attached later using the _configure_property manually as above.

Cheers,
Ahmed

On Saturday, July 13, 2013 3:18:47 PM UTC+9:30, Ahmed wrote:

 Hello all,

 I have the following scenario:
 I have 5 or 6 related sqlalchemy declarative models sitting in a pyramid 
 app. This occurs in the context of extending a pyramid application, where I 
 import/config.scan() these selected models from another pyramid app into a 
 new app. The thing is that these models have the original app's declarative 
 base and I need them to work with the new app's declarative base.

 So I tried to change their declarative base upon importing. (also with 
 giving a new name to avoid possible name collisions)
 This was my approach:
 newmodel = type(newmodelname, (newdeclarativebase, oldmodel), {})

 which worked out pretty well!!! except for one nuisance, which is that 
 already instrumented relationships are still bound to the old models 
 instead of the new ones.

 class OldParentModel(oldbase):
 rel = relationship(OldChildModel)

  new = query(NewParentModel).first()
  new.rel
   [oldapp.models.OldChildModel at 0xb1cbfac]

 I wished that they are linked to NewChildModel instead.

 so is there a way to avoid this problem or at least remap the already 
 mapped relationships to the new models? 
 Or perhaps a whole different approach to dealing with this (without 
 actually redefining the whole classes again in the new app)?

 Cheers,
 Ahmed


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] Changing the declarative base of a class and re-mapping

2013-07-12 Thread Ahmed
Hello all,

I have the following scenario:
I have 5 or 6 related sqlalchemy declarative models sitting in a pyramid 
app. This occurs in the context of extending a pyramid application, where I 
import/config.scan() these selected models from another pyramid app into a 
new app. The thing is that these models have the original app's declarative 
base and I need them to work with the new app's declarative base.

So I tried to change their declarative base upon importing. (also with 
giving a new name to avoid possible name collisions)
This was my approach:
newmodel = type(newmodelname, (newdeclarativebase, oldmodel), {})

which worked out pretty well!!! except for one nuisance, which is that 
already instrumented relationships are still bound to the old models 
instead of the new ones.

class OldParentModel(oldbase):
rel = relationship(OldChildModel)

 new = query(NewParentModel).first()
 new.rel
  [oldapp.models.OldChildModel at 0xb1cbfac]

I wished that they are linked to NewChildModel instead.

so is there a way to avoid this problem or at least remap the already 
mapped relationships to the new models? 
Or perhaps a whole different approach to dealing with this (without 
actually redefining the whole classes again in the new app)?

Cheers,
Ahmed

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.




[sqlalchemy] Adapting the polymorphic association example for generic reuse

2011-10-02 Thread Ahmed
I am looking at 
http://www.sqlalchemy.org/trac/browser/examples/generic_associations/discriminator_on_association.py
and trying to adapt the example to one that is generic and can be
reused. So I attempted to abstract all the classes. However there
seems to be an error in the __new__ function of the creator object.

CODE is here
http://pastebin.com/4DyK47r3

ERROR is here:
Traceback (most recent call last):
File sqlalchemyex.py, line 136, in module
zip=95732)
File string, line 4, in __init__
File /home/ahmed/dev/pyrenv/lib/python2.6/site-packages/
SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/orm/state.py, line 111, in
initialize_instance
return manager.events.original_init(*mixed[1:], **kwargs)
File /home/ahmed/dev/pyrenv/lib/python2.6/site-packages/
SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/ext/declarative.py, line 1378,
in _declarative_constructor
setattr(self, k, kwargs[k])
File /home/ahmed/dev/pyrenv/lib/python2.6/site-packages/
SQLAlchemy-0.6.6-py2.6.egg/sqlalchemy/ext/associationproxy.py, line
195, in __set__
setattr(obj, self.target_collection, creator(values))
File sqlalchemyex.py, line 28, in lambda
discriminator=discriminator)
TypeError: object.__new__() takes no parameters


Can anyone please help me understand what am I doing wrong? I guess if
I know what's causing the error, then the code after some polishing
will be a good candidate to include in the SQLalchemy recipes.

Cheers,
Ahmed
http://stackoverflow.com/questions/7582861

-- 
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: InstrumentedList/InstrumentedAttribute to dynamic query

2011-08-24 Thread Ahmed
It seems I am very close to an answer by Michael Bayer demonstrated in
that thread:
http://groups.google.com/group/sqlalchemy/browse_thread/thread/2f60ee62e1ed6a0a

I changed the strategies on the class mapper RelationshipProperties as
follows:

def make_dynamic(sqlalchemy_class):
mapper = class_mapper(sqlalchemy_class)

for prop in mapper.iterate_properties:
if isinstance(prop, RelationshipProperty):
prop.strategy_class = strategies.factory('dynamic')
interfaces.StrategizedProperty.do_init(prop)

changing the strategy to subquery seems to be working fine (sql
queries run in console on instance loading), however changing that to
'dynamic' does not get the same effect and I still have normal
instrumented lists instead of appender queries.

Any clues? I appreciate your help.

Cheers,
Ahmed


On Aug 22, 5:04 pm, Ahmed ahmedba...@gmail.com wrote:
 Hello,
 I wonder if there is a possibility given an object instance (say with
 an InstrumentedList of a relationship attribute).. to get a
 corresponding dynamic query of this same InstrumentedList (the List
 was configured in the declarative class with a lazy loader and not a
 dynamic loader)??

 Cheers

-- 
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] InstrumentedList/InstrumentedAttribute to dynamic query

2011-08-22 Thread Ahmed
Hello,
I wonder if there is a possibility given an object instance (say with
an InstrumentedList of a relationship attribute).. to get a
corresponding dynamic query of this same InstrumentedList (the List
was configured in the declarative class with a lazy loader and not a
dynamic loader)??

Cheers

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

2011-05-30 Thread Ahmed
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.



[sqlalchemy] Re: Problem accessing sqlite records w primary keys imported from csv file

2011-05-30 Thread Ahmed Bassiouni
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.