[sqlalchemy] How to filter relations?

2009-09-11 Thread Eloff

On most of my tables I have the concept of an owner, a reference to
the user who created the row. On most of my other relations, I need to
filter by owner==current_user.

All the classes that have an owner are marked (separate parent class,
I'm using elixir) so I could probably come up with a general solution.
An idea of how to do this might be to define:

def __getattr__(self, attr):
 rel_attr = attr + '_id'
 field = getattr(self.table.c, rel_attr, None)
 if field and field.foreign_keys:
  rel_table = field.foreign_keys[0].constraint.table
  objs = meta.Session.query(rel_table).filter
(owner_id==current_user.id).all()
  setattr(self, attr, objs) # XXX not sure that this is a good
idea
  return objs

 # XXX quite sure this won't work, maybe need to call super(Me,
self).__getattr__(attr) ?
 raise AttributeError(attr)

If you have some advice on the XXX comments above or an idea to
improve the solution / better solution, please give me a hand.

Thanks,
-Dan
--~--~-~--~~~---~--~~
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] Cascade option, what does all mean?

2009-09-08 Thread Eloff

Hi,

I see cascade='all, delete, delete-orphan' in the tutorial, but I
thought I read in the docs elsewhere (can't seem to find the place
atm) that all includes merge, delete, and others so that cascade='all,
delete-orphan' should be equivalent?

Is this correct?

Thanks,
-Dan
--~--~-~--~~~---~--~~
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: How to bypass scoped_session?

2009-09-08 Thread Eloff

On Sep 8, 3:47 am, King Simon-NFHD78 simon.k...@motorola.com
wrote:
 Automatically adding objects to a session when they are created is a
 feature of Session.mapper (rather than the plain orm.mapper function),
 and is deprecated. If you use the plain mapper function, all root
 objects that you create will have to be explicitly added to a session.
 (related objects will normally be added by default)

That makes sense to me.

 Session.mapper also included a couple of extra features (the 'query'
 property and a default __init__) which you can recreate yourself using
 the examples at
 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper

Trouble is I am using elixir, so I'm not sure I can change this
behavior.

Thanks Simon,

-Dan
--~--~-~--~~~---~--~~
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] How to avoid attribute refresh?

2009-09-07 Thread Eloff

Hi All,

Have a look at this traceback, entry.value is a Site object returned
from a query, accessing id (5 lines from the bottom) seems to trigger
an attribute refresh. Obviously this defeats the point of the caching
I'm doing. If I avoid any of the relations on the Site object, for
read-only access, can I also avoid attribute refresh? (maybe I erred
by not expunging the Site object from the session before placing it in
the cache?)

http://pylonshq.com/tracebacks/1f0d4adf753700839add5bba408dde9f

-Dan
--~--~-~--~~~---~--~~
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: How to avoid attribute refresh?

2009-09-07 Thread Eloff


On Sep 7, 3:11 pm, Michael Bayer mike...@zzzcomputing.com wrote:

 you want to make sure things are cached (which means they've been  
 pickled and therefore not related to the Session anymore) before the  
 Session is expired, which happens when you call rollback() or commit()  
 (or expunged, sure, though that's usually too much trouble - just the  
 pickling part of the story takes care of that usually).    
 alternatively you can disable expire_on_commit if that's what's  
 getting in the way.

Thanks, that did the trick. For the one cache I added the one line of
code to expunge the objects first. For the other I copied the
important data out into a namedtuple and saved myself some memory too.

Cheers,
-Dan
--~--~-~--~~~---~--~~
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] How to bypass scoped_session?

2009-09-07 Thread Eloff

Hi,

I'm using scoped_session in my pylons app, but sometimes I have a need
to create a local session, do a little work, and commit it without
worrying about the current state of the scoped_session (i.e. without
committing it)

I'm having some issues with that because the minute I create a new
object, it gets associated (as transient I guess?) with the
scoped_session and barfs when I add it to the local session (object is
already in a session.)

The best I've found is expunge() from the scoped_session after init,
then the add will work without issues.

Is there any way to create objects without them being added to
scoped_session? I don't see that there is any way with a regular
session that they'd be added on init, so it can't be required
functionality. Maybe there's an option to disable it?

I can't imagine what it is good for, but that's probably just failure
of imagination on my part.

Thanks,
-Dan
--~--~-~--~~~---~--~~
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: any effort getting sqlalchemy to work on ironpython is going on ?

2008-09-13 Thread Dan Eloff

On Thu, Sep 11, 2008 at 10:01 PM, sakesun [EMAIL PROTECTED] wrote:

 Traceback (most recent call last):
  File stdin, line 1, in module
 IndexError: Index was outside the bounds of the array.


I've had that before on complex python packages (e.g. Jinja2), I'm
pretty sure it's an internal error in IronPython, but beats me as to
where it's happening. You should try running it under the debugger.

-Dan

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] ConcurrentModificationError without concurrent modification?

2007-10-01 Thread Dan Eloff

ConcurrentModificationError: Deleted rowcount 3 does not match number
of objects deleted 1

raised by this code:

with Session() as session:
dl = session.merge(dl)
session.delete(dl)

There are no other sessions alive, so how can that possibly be a
concurrent modification?

Using sqlalchemy 0.4 beta 5, python 2.5, sqllite.

dl has a many-to-many relationship associated with it.

Any ideas why this is happening?

Thanks,
-Dan

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: ConcurrentModificationError without concurrent modification?

2007-10-01 Thread Dan Eloff

On 10/1/07, Michael Bayer [EMAIL PROTECTED] wrote:

 most likely too many association rows are present in the m2m table.


Do you mean there were redundant associations? How can I check if
that's the cause of the problem?

Thanks,
-Dan

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: backref relation is None instead of list?

2007-09-10 Thread Dan Eloff

On 9/9/07, Michael Bayer [EMAIL PROTECTED] wrote:
 I cant reproduce this, although the error to me seems like you are
 actually saying c._parent = [] (some list object).  If thats not it,
 send along a reproducing test script.

I tried to recreate it in the shell and failed.

I then loaded my application, changed _parents to parent and it just
worked. I don't think the change did it, I think it just disappeared
(maybe the reboot?) If it happens again I'll post it on this mailing
list.

Thanks for the tip about one-to-many relations, I was hoping they
worked like that, but when I got the errors I assumed it must not.

Sorry for the false alarm,

-Dan

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---