[sqlalchemy] Re: Preventing attribute expiration (0.7, ORM)

2011-06-20 Thread Maciej Szumocki
On 17 Cze, 16:20, Michael Bayer  wrote:

> I usually just turn expire_on_commit = False.      But note also if you just 
> want to do a get(), the actual PK is always present in the "key", which is 
> instance_state(myinstance).key[1].

I do want rest of the attributes to expire, which makes
expire_on_commit = False not practical.
But i need (read-only) access to primary key attribute in another
thread, and a guarantee that this access won't result in any database
queries.
Can you perhaps suggest another solution?

Maciej Szumocki

-- 
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] Preventing attribute expiration (0.7, ORM)

2011-06-16 Thread Maciej Szumocki
Hi all,

I have a question for SA 0.7. Is there a way to prevent expiration of
some of the attributes of a mapped object
(without detaching the object from session). I have a use case where
primary keys are immutable (they're only
INSERTed, never UPDATEd), and i'd like to able to always access them
without potientally triggering a refresh
(in other words, those attributes should be available if objects were
loaded even if database connection goes away).
I was able to achieve that in 0.6 and earlier with lots of
monkeypatching, but can't seem to find a way to do the
same in 0.7.

Maciej Szumocki

-- 
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: SqlAlchemy limiting returned rows prematurely

2009-06-30 Thread Maciej Szumocki

I think the problem might be not the query itself, but the date ranges
that get converted using wrong date format. Do you get the same
results if you use real datetime objects instead of strings there?
--~--~-~--~~~---~--~~
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: Eager load working differently?

2006-10-24 Thread Maciej Szumocki


Michael Bayer wrote:
> use backref=backref(somename, lazy=False, ).

I tried changing backrefs to "backref=backref('middle', lazy=False)" in
the above test script, but
hit another issue then:

Traceback (most recent call last):
  File "C:\svn\devel\utils\eagerload.py", line 66, in ?
test(False) # will work fine
  File "C:\svn\devel\utils\eagerload.py", line 57, in test
obj = session.query(Left).get_by(tag='tag1')
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\query.py", line 95, in
get_by
x = self.select_whereclause(self.join_by(*args, **params), limit=1)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\query.py", line 256, in
select_whereclause
return self._select_statement(statement, params=params)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\query.py", line 372, in
_select_statement
return self.execute(statement, params=params, **kwargs)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\query.py", line 304, in
execute
return self.instances(result, **kwargs)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\query.py", line 323, in
instances
self.mapper._instance(context, row, result)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1177, in
_instance
self.populate_instance(context, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1212, in
populate_instance
prop.execute(selectcontext, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\interfaces.py", line 77,
in execute

self._get_context_strategy(selectcontext).process_row(selectcontext,
instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\strategies.py", line 489,
in process_row
instance.__dict__[self.key] = self.mapper._instance(selectcontext,
decorated_row, None)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1177, in
_instance
self.populate_instance(context, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1212, in
populate_instance
prop.execute(selectcontext, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\interfaces.py", line 77,
in execute

self._get_context_strategy(selectcontext).process_row(selectcontext,
instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\strategies.py", line 511,
in process_row
self.mapper._instance(selectcontext, decorated_row, result_list)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1177, in
_instance
self.populate_instance(context, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1212, in
populate_instance
prop.execute(selectcontext, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\interfaces.py", line 77,
in execute

self._get_context_strategy(selectcontext).process_row(selectcontext,
instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\strategies.py", line 489,
in process_row
instance.__dict__[self.key] = self.mapper._instance(selectcontext,
decorated_row, None)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1177, in
_instance
self.populate_instance(context, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 1212, in
populate_instance
prop.execute(selectcontext, instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\interfaces.py", line 77,
in execute

self._get_context_strategy(selectcontext).process_row(selectcontext,
instance, row, identitykey, isnew)
  File "c:\svn\sqlalchemy\lib\sqlalchemy\orm\strategies.py", line 505,
in process_row
result_list = selectcontext.attributes[(instance, self.key)]
KeyError: (<__main__.Middle object at 0x00D7A910>, 'left')


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Eager load working differently?

2006-10-23 Thread Maciej Szumocki

After some more testing (the use of loggers in sqlalchemy helped alot
:)) i have narrowed the issue to backreference creation - they seem to
be always created lazy, even if relation is set to eager. Here's a
simple test script (not in unittest format unfortunately as i'm not
sure how to make one that would work within sqlalchemy unittest
framework).

from sqlalchemy import *
dburi = "put your own here"

import logging
#logging.getLogger("sqlalchemy.orm.mapper.Mapper").setLevel(1)
#logging.getLogger("sqlalchemy.orm.strategies.EagerLoader").setLevel(1)
#uncomment if you want to see what exactly is going on

engine = create_engine(dburi, strategy='plain', echo=True)
metadata = BoundMetaData(engine)

middle = Table('middle', metadata,
Column('id', Integer, primary_key = True, autoincrement=True),
Column('data', String(50)),
)

left = Table('left', metadata,
Column('id', Integer, ForeignKey(middle.c.id), primary_key=True),
Column('tag', String(50), primary_key=True),
)

right = Table('right', metadata,
Column('id', Integer, ForeignKey(middle.c.id), primary_key=True),
Column('tag', String(50), primary_key=True),
)

class Middle(object):
def __init__(self, data): self.data = data
class Left(object):
def __init__(self, data): self.tag = data
class Right(object):
def __init__(self, data): self.tag = data

mapper(Left, left)
mapper(Right, right)
mapper(Middle, middle, properties = {
'left': relation(Left, private=True, lazy=False, backref='middle',
foreignkey=left.c.id,  primaryjoin = left.c.id==middle.c.id ),
'right': relation(Right, private=True, lazy=False,
backref='middle',
foreignkey=right.c.id,  primaryjoin = right.c.id==middle.c.id
),
}
)

def make_data():
session = create_session(bind_to=engine)
p = Middle('test1')
p.left.append(Left('tag1'))
p.right.append(Right('tag2'))
session.save(p)
session.flush()

def test(close_session):
session = create_session(bind_to=engine)
obj = session.query(Left).get_by(tag='tag1')
if close_session:
session.close()
print obj.middle.right[0]

if __name__=="__main__":
metadata.create_all()
try:
make_data()
test(False) # will work fine
test(True) # will fail
finally:
metadata.drop_all()


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~--~~~~--~~--~--~---



[sqlalchemy] Eager load working differently?

2006-10-20 Thread Maciej Szumocki

I started to get exceptions like this one:

   sqlalchemy.exceptions.InvalidRequestError: Parent instance  is not bound to a Session, and
no contextual session is established; lazy load operation of attribute
'_properties' cannot proceed

However, my mappers are defined like this (and used to eagerly load
_properties attribute fine some SVN revisions ago):

_objectMapper = mapper(DatabaseObject, objects, properties = {
'_properties': relation(ObjectProperty, private=True, lazy=False,
foreignkey=object_properties.c.id,  primaryjoin =
object_properties.c.id==objects.c.id ),
}
)

Any hints as to what do i need to fix to make it work again?


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~--~~~~--~~--~--~---