[sqlalchemy] How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Esceo

Hi, all

the followings are the code snippet

from sqlalchemy import *
meta = MetaData('sqlite://')

parent = Table('parent', meta,
Column('id', Integer, primary_key=True),
Column('name', Integer)
)

child = Table('child', meta,
Column('id', Integer, primary_key=True),
Column('current_id', Integer),
Column('parent_id', Integer),
ForeignKeyConstraint(['parent_id'],['parent.id'],
ondelete=CASCADE),
ForeignKeyConstraint(['current_id'],['child.id']), )

class Parent(object):
   pass

class Child(object):
   pass

mapper(Parent, parent);

mapper(Child, child,
properties = { 'parent' : relation(Parent,
primaryjoin =
(child.c.parent_id == parent.c.id) 
(child.c.current_id ==
child.c.id),
backref = child),
'current' : relation(Child,
primaryjoin = child.c.current_id ==
child.c.id)
})

meta.create_all()

s = create_session()
c = Child()
c.parent = Parent()
s.save(c)
s.flush()
s.clear()

running that resulted in

Traceback (most recent call last):
  File C:\powerforce\test_fk_relation.py, line 39, in module
s.flush()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\session.py, line 320, in flush
self.uow.flush(self, objects)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 210, in flush
flush_context.execute()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 400, in execute
UOWExecutor().execute(self, head)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1018, in execute
self.execute_save_steps(trans, task)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1035, in
execute_save_steps
self.execute_dependencies(trans, task, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1048, in
execute_dependencies
self.execute_dependency(trans, dep, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1029, in
execute_dependency
dep.execute(trans, isdelete)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\unitofwork.py, line 984, in execute
self.processor.process_dependencies(self.targettask, [elem.obj for
elem in self.targettask.polymorphic_tosave_elements if elem.obj is not
None], trans, delete=False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\dependency.py, line 275, in
process_dependencies
self._synchronize(obj, child, None, False, uowcommit)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\dependency.py, line 310, in _synchronize
self.syncrules.execute(source, dest, obj, child, clearkeys)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\sync.py, line 92, in execute
rule.execute(source, dest, obj, child, clearkeys)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\sync.py, line 135, in execute
value = self.source_mapper.get_attr_by_column(source,
self.source_column)
  File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\mapper.py, line 1017, in get_attr_by_column
prop = self._getpropbycolumn(column, raiseerror)
  File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
py2.5.egg\sqlalchemy\orm\mapper.py, line 1007, in _getpropbycolumn
raise exceptions.InvalidRequestError(Column '%s.%s' is not
available, due to conflicting property '%s':%s % (column.table.name,
column.name, column.key, repr(prop)))
sqlalchemy.exceptions.InvalidRequestError: Column 'child.id' is not
available, d
ue to conflicting property
'id':sqlalchemy.orm.properties.ColumnProperty object at 0x016FB730

If I had renamed the id column on child to '_id', I ended up with a
different error no child.id column configured on the maper Parent|
parent|

any clues?

Thanks in advance

Lei


--~--~-~--~~~---~--~~
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: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Esceo

Just wondering if this is a bug in _determine_fks

i.e. 'child.id'  probably should not be part of the foreign key
pointing to parent


On Nov 6, 7:42 pm, Esceo [EMAIL PROTECTED] wrote:
 Hi, all

 the followings are the code snippet

 from sqlalchemy import *
 meta = MetaData('sqlite://')

 parent = Table('parent', meta,
 Column('id', Integer, primary_key=True),
 Column('name', Integer)
 )

 child = Table('child', meta,
 Column('id', Integer, primary_key=True),
 Column('current_id', Integer),
 Column('parent_id', Integer),
 ForeignKeyConstraint(['parent_id'],['parent.id'],
 ondelete=CASCADE),
 ForeignKeyConstraint(['current_id'],['child.id']), )

 class Parent(object):
pass

 class Child(object):
pass

 mapper(Parent, parent);

 mapper(Child, child,
 properties = { 'parent' : relation(Parent,
 primaryjoin =
 (child.c.parent_id == parent.c.id) 
 (child.c.current_id ==
 child.c.id),
 backref = child),
 'current' : relation(Child,
 primaryjoin = child.c.current_id ==
 child.c.id)

 })

 meta.create_all()

 s = create_session()
 c = Child()
 c.parent = Parent()
 s.save(c)
 s.flush()
 s.clear()

 running that resulted in

 Traceback (most recent call last):
   File C:\powerforce\test_fk_relation.py, line 39, in module
 s.flush()
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\session.py, line 320, in flush
 self.uow.flush(self, objects)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 210, in flush
 flush_context.execute()
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 400, in execute
 UOWExecutor().execute(self, head)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1018, in execute
 self.execute_save_steps(trans, task)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1035, in
 execute_save_steps
 self.execute_dependencies(trans, task, False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1048, in
 execute_dependencies
 self.execute_dependency(trans, dep, False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1029, in
 execute_dependency
 dep.execute(trans, isdelete)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 984, in execute
 self.processor.process_dependencies(self.targettask, [elem.obj for
 elem in self.targettask.polymorphic_tosave_elements if elem.obj is not
 None], trans, delete=False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\dependency.py, line 275, in
 process_dependencies
 self._synchronize(obj, child, None, False, uowcommit)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\dependency.py, line 310, in _synchronize
 self.syncrules.execute(source, dest, obj, child, clearkeys)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\sync.py, line 92, in execute
 rule.execute(source, dest, obj, child, clearkeys)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\sync.py, line 135, in execute
 value = self.source_mapper.get_attr_by_column(source,
 self.source_column)
   File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\mapper.py, line 1017, in get_attr_by_column
 prop = self._getpropbycolumn(column, raiseerror)
   File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\mapper.py, line 1007, in _getpropbycolumn
 raise exceptions.InvalidRequestError(Column '%s.%s' is not
 available, due to conflicting property '%s':%s % (column.table.name,
 column.name, column.key, repr(prop)))
 sqlalchemy.exceptions.InvalidRequestError: Column 'child.id' is not
 available, d
 ue to conflicting property
 'id':sqlalchemy.orm.properties.ColumnProperty object at 0x016FB730

 If I had renamed the id column on child to '_id', I ended up with a
 different error no child.id column configured on the maper Parent|
 parent|

 any clues?

 Thanks in advance

 Lei


--~--~-~--~~~---~--~~
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] mapper

2007-11-06 Thread lur ibargutxi

Hi everyone!
I'm new in SQLAlchemy and this is my code:

mappers['indicatorgroups'] = mapper(IndicatorGroups, tables['indicatorgroups'])

mappers['groupgroups'] = mapper(GroupGroups, tables['groupgroups'],
properties = {

'idindicatorgroupcontainer' : relation(IndicatorGroups,
primaryjoin=sql.and_(IndicatorGroups.idindicatorgroup==GroupGroups.idindicatorgroupcontainer)),'idindicatorgroupcontained'
: relation(IndicatorGroups,
primaryjoin=sql.and_(IndicatorGroups.idindicatorgroup==GroupGroups.idindicatorgroupcontained)),
},allow_column_override=True)

when i do:

 g=IndicatorGroups()

I have this error:
Module sqlalchemy.sql.visitors, line 56, in traverse
AttributeError: 'bool' object has no attribute 'get_children'

I don't know how to fix this. Does anyone knows about this problem??

Thanks a lot


Module sqlalchemy.sql.visitors, line 56, in traverse
AttributeError: 'bool' object has no attribute 'get_children'

-- 
Lur Ibargutxi
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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: mapper

2007-11-06 Thread Marco Mariani

lur ibargutxi wrote:

 'idindicatorgroupcontainer' : relation(IndicatorGroups,
 primaryjoin=sql.and_(IndicatorGroups.idindicatorgroup==GroupGroups.idindicatorgroupcontainer)),'idindicatorgroupcontained'
 : relation(IndicatorGroups,
 primaryjoin=sql.and_(IndicatorGroups.idindicatorgroup==GroupGroups.idindicatorgroupcontained)),
 },allow_column_override=True)

 when i do:

  g=IndicatorGroups()

 I have this error:
 Module sqlalchemy.sql.visitors, line 56, in traverse
 AttributeError: 'bool' object has no attribute 'get_children'

 I don't know how to fix this. Does anyone knows about this problem??
   

You are using and_() over a single parameter.

Moreover, you're probably using SA  0.4 and you need to use 
IndicatorGroups.c.indicatorgroup

Note the '.c.' -- that goes away with the 0.4 API overhaul. So either 
upgrade SA, or use the .c attribute

You don't usually need to keep a reference to the mappers, you can 
always get them from the mapped classes.


--~--~-~--~~~---~--~~
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: mapper

2007-11-06 Thread Marco Mariani

lur ibargutxi wrote:

I forgot. Try using tables instead of classes that are not mapped yet..

mappers['groupgroups'] = mapper(GroupGroups, tables['groupgroups'],
properties = {

'idindicatorgroupcontainer' : relation(IndicatorGroups,
primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontainer)),'idindicatorgroupcontained'
: relation(IndicatorGroups,
primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontained)),
},allow_column_override=True)




--~--~-~--~~~---~--~~
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: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Esceo

the fix? was to add a check for self referential foreign keys in non-
self-referential relations, and do not add those as part of the
relation's foreign key collection,

is this anywhere near the correct thing to do?

# ignore self referential keys
if not (self.secondaryjoin or
self._is_self_referential() or binary.left.table !=
binary.right.table):
return


def _determine_fks(self):
if len(self._legacy_foreignkey) and not
self._is_self_referential():
self.foreign_keys = self._legacy_foreignkey

def col_is_part_of_mappings(col):
if self.secondary is None:
return
self.parent.mapped_table.corresponding_column(col, raiseerr=False) is
not None or \
self.target.corresponding_column(col,
raiseerr=False) is not None
else:
return
self.parent.mapped_table.corresponding_column(col, raiseerr=False) is
not None or \
self.target.corresponding_column(col,
raiseerr=False) is not None or \
self.secondary.corresponding_column(col,
raiseerr=False) is not None

if len(self.foreign_keys):
self._opposite_side = util.Set()
def visit_binary(binary):
if binary.operator != '=' or not
isinstance(binary.left, schema.Column) or not isinstance(binary.right,
schema.Column):
return
if binary.left in self.foreign_keys:
self._opposite_side.add(binary.right)
if binary.right in self.foreign_keys:
self._opposite_side.add(binary.left)
 
mapperutil.BinaryVisitor(visit_binary).traverse(self.primaryjoin)
if self.secondaryjoin is not None:
 
mapperutil.BinaryVisitor(visit_binary).traverse(self.secondaryjoin)
else:
self.foreign_keys = util.Set()
self._opposite_side = util.Set()
def visit_binary(binary):
if binary.operator != '=' or not
isinstance(binary.left, schema.Column) or not isinstance(binary.right,
schema.Column):
return

# this check is for when the user put the view_only
flag on and has tables that have nothing
# to do with the relationship's parent/child mappings
in the join conditions.  we dont want cols
# or clauses related to those external tables dealt
with.  see orm.relationships.ViewOnlyTest
if not col_is_part_of_mappings(binary.left) or not
col_is_part_of_mappings(binary.right):
return

# ignore self referential keys
if not (self.secondaryjoin or
self._is_self_referential() or binary.left.table !=
binary.right.table):
return

for f in binary.left.foreign_keys:
if f.references(binary.right.table):
self.foreign_keys.add(binary.left)
self._opposite_side.add(binary.right)
for f in binary.right.foreign_keys:
if f.references(binary.left.table):
self.foreign_keys.add(binary.right)
self._opposite_side.add(binary.left)
 
mapperutil.BinaryVisitor(visit_binary).traverse(self.primaryjoin)

if len(self.foreign_keys) == 0:
raise exceptions.ArgumentError(
Can't locate any foreign key columns in primary
join 
condition '%s' for relationship '%s'.  Specify 
'foreign_keys' argument to indicate which columns
in 
the join condition are foreign. %
(str(self.primaryjoin), str(self)))
if self.secondaryjoin is not None:
 
mapperutil.BinaryVisitor(visit_binary).traverse(self.secondaryjoin)

On Nov 6, 9:11 pm, Esceo [EMAIL PROTECTED] wrote:
 Just wondering if this is a bug in _determine_fks

 i.e. 'child.id'  probably should not be part of the foreign key
 pointing to parent

 On Nov 6, 7:42 pm, Esceo [EMAIL PROTECTED] wrote:



  Hi, all

  the followings are the code snippet

  from sqlalchemy import *
  meta = MetaData('sqlite://')

  parent = Table('parent', meta,
  Column('id', Integer, primary_key=True),
  Column('name', Integer)
  )

  child = Table('child', meta,
  Column('id', Integer, primary_key=True),
  Column('current_id', Integer),
  Column('parent_id', Integer),
  ForeignKeyConstraint(['parent_id'],['parent.id'],
  ondelete=CASCADE),
  ForeignKeyConstraint(['current_id'],['child.id']), )

  class Parent(object):
 pass

  class Child(object):
 pass

  mapper(Parent, parent);

  mapper(Child, child,
  properties = { 'parent' : relation(Parent,
  primaryjoin =
  (child.c.parent_id == parent.c.id) 
  (child.c.current_id ==
  child.c.id),
  

[sqlalchemy] Re: mapper

2007-11-06 Thread lur ibargutxi

thanks a lot. That's the solution.

2007/11/6, Marco Mariani [EMAIL PROTECTED]:

 lur ibargutxi wrote:

 I forgot. Try using tables instead of classes that are not mapped yet..

 mappers['groupgroups'] = mapper(GroupGroups, tables['groupgroups'],
 properties = {

 'idindicatorgroupcontainer' : relation(IndicatorGroups,
 primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontainer)),'idindicatorgroupcontained'
 : relation(IndicatorGroups,
 primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontained)),
 },allow_column_override=True)




 



-- 
Lur Ibargutxi
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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] Can I have an integer primary keys that is not a sequence?

2007-11-06 Thread Christoph Zwerschke

If I define a table like that:

Table('t', metadata, Column('c', Integer, primary_key=True))

then SQLAlchemy creates the column c as a SERIAL on PostgreSQL.

Is there a way to tell SQLAlchemy to create an ordinary integer primary
key, without any associated sequence?

-- Chris

--~--~-~--~~~---~--~~
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: Can I have an integer primary keys that is not a sequence?

2007-11-06 Thread Paul Johnston
Hi,

Is there a way to tell SQLAlchemy to create an ordinary integer primary
 key, without any associated sequence?


Sure... autoincrement=False

Paul

--~--~-~--~~~---~--~~
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: Can I have an integer primary keys that is not a sequence?

2007-11-06 Thread Christoph Zwerschke

Paul Johnston wrote:
 Is there a way to tell SQLAlchemy to create an ordinary integer primary
 key, without any associated sequence? 
 
 Sure... autoincrement=False

Thanks a lot. Found it now in the API docs.

I propose that this (and the fact that it is True by default) be also
mentioned somewhere in the main docs.

-- Chris

--~--~-~--~~~---~--~~
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] A Query object seems to be altered by a count() - is this a bug?

2007-11-06 Thread klaus

Hi all,
when I try to build up a complicated query like this:

query = session.query(Class)
query = query.filter_by(...).add_entity(...).join(...)
count = query.count()
query = query.add_entity(...).join(...).order_by(...)
print query.all()

the last statement fails due to a broken SELECT. The error disappears
if I remove the line with the query.count().

The following is an example to reproduce the behavior. I'm sorry that
it is so complicated, but a certain complexity seems to be necessary
to trigger the bug.


--~--~-~--~~~---~--~~
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] bug with negative slices in orm.query.Query.__getitem__?

2007-11-06 Thread Simon Wittber

Slicing of Query instances can return inconsistent types if negative
stop/start values are used.

The below patch to tes/orm/query.py demonstrates the issue. When
slices with negative stop/start values are used, a list type is
returned. When positive values are used, a Query instance is returned.
Is this a bug?

If this is a bug, I might be able to fix it, but I'm not sure what a
slice should return. Should a list be returned from a slice operation,
or should a Query instance be returned?


Index: orm/query.py
===
--- orm/query.py(revision 3743)
+++ orm/query.py(working copy)
@@ -5,6 +5,7 @@
 from sqlalchemy.sql import compiler
 from sqlalchemy.engine import default
 from sqlalchemy.orm import *
+from sqlalchemy.orm import query
 from testlib import *
 from testlib import engines
 from testlib.fixtures import *
@@ -268,6 +269,11 @@
 def test_basic(self):
 assert [User(id=7), User(id=8), User(id=9),User(id=10)] ==
create_session().query(User).all()

+def test_negative_slices(self):
+s = create_session()
+assert type(s.query(Address).filter(Address.user_id==8)[1:3])
is query.Query
+assert type(s.query(Address).filter(Address.user_id==8)
[-2:-1]) is query.Query
+
 @testing.fails_on('maxdb')
 def test_limit(self):
 assert [User(id=8), User(id=9)] ==
create_session().query(User).limit(2).offset(1).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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: A Query object seems to be altered by a count() - is this a bug?

2007-11-06 Thread klaus

Sorry, I was not finished yet.

The outline is a follows: I want to join three relations unary o
nullary o squared, where squared = binary^2, and find out which
elements n are in relation n (unary o nullary o squared) fixed to some
nullary element fixed.

Here are the details:

from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData(...)
metadata.bind.echo=True

nullary = Table(nullary, metadata,
Column(id, Integer, primary_key=True),
Column(data, String))

nullary.create()

nullary.insert().execute([{data: 1}, {data: 2}])

class Nullary(object):
pass

mapper(Nullary, nullary)

unary = Table(unary, metadata,
  Column(id, Integer, primary_key=True),
  Column(fk, Integer, ForeignKey(nullary.id)))

unary.create()

unary.insert().execute([{fk: 1}, {fk: 2}])

class Unary(object):
pass

mapper(Unary, unary,
   properties={ref: relation(Nullary, uselist=False,
backref=inv)})

binary = Table(binary, metadata,
   Column(id, Integer, primary_key=True),
   Column(fk1, Integer, ForeignKey(nullary.id)),
   Column(fk2, Integer, ForeignKey(nullary.id)))

binary.create()

binary.insert().execute([{fk1: 1, fk2: 1}, {fk1: 2, fk2: 2}])

class Binary(object):
pass

mapper(Binary, binary,
   properties={ref1: relation(Nullary, uselist=False,
primaryjoin=binary.c.fk1 ==
nullary.c.id),
   ref2: relation(Nullary, uselist=False,
primaryjoin=binary.c.fk2 ==
nullary.c.id)})

binary_alias = binary.alias(binary_alias)

squared = select([binary.c.fk1.label(fk1),
  binary_alias.c.fk2.label(fk2),
  func.count(text(*)).label(n)],
 True,
 [join(binary, binary_alias,
   binary.c.fk2 == binary_alias.c.fk1)])
squared = squared.group_by(binary.c.fk1,
binary_alias.c.fk2).alias(squared)

class Squared(object):
pass

mapper(Squared, squared, primary_key=(squared.c.fk1, squared.c.fk2),
 properties={ref1: relation(Nullary),
 ref2: relation(Nullary)})

session = create_session()

fixed = session.query(Nullary).get(1)

query = session.query(Squared).filter_by(ref2=fixed)
query = query.add_entity(Nullary).join(ref1)
count = query.count()
query = query.add_entity(Unary).join(inv, from_joinpoint=True)
query = query.order_by([squared.c.n])
print [n for s, n, u in query]


The traceback:

2007-11-06 15:57:34,122 INFO sqlalchemy.engine.base.Engine.0x..94
ROLLBACK
Traceback (most recent call last):
  File wrong_select4.py, line 117, in ?
print [n for s, n, u in query]
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/orm/query.py, line
630, in __iter__
return self._execute_and_instances(context)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/orm/query.py, line
633, in _execute_and_instances
result = self.session.execute(querycontext.statement,
params=self._params, mapper=self.mapper)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/orm/session.py, line
527, in execute
return self.__connection(engine,
close_with_result=True).execute(clause, params or {}, **kwargs)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/engine/base.py, line
781, in execute
return Connection.executors[c](self, object, multiparams, params)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/engine/base.py, line
832, in _execute_clauseelement
return self._execute_compiled(elem.compile(dialect=self.dialect,
column_keys=keys, inline=len(params)  1), distilled_params=params)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/engine/base.py, line
844, in _execute_compiled
self.__execute_raw(context)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/engine/base.py, line
856, in __execute_raw
self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
  File /home/barthelmannk/local/lib/python.new/
SQLAlchemy-0.4.1dev_r3733-py2.4.egg/sqlalchemy/engine/base.py, line
872, in _cursor_execute
raise exceptions.DBAPIError.instance(statement, parameters, e)
sqlalchemy.exceptions.ProgrammingError: (ProgrammingError) invalid
reference to FROM-clause entry for table nullary
HINT:  There is an entry for table nullary, but it cannot be
referenced from this part of the query.
 'SELECT squared.fk1 AS squared_fk1, squared.fk2 AS squared_fk2,
squared.n AS squared_n, nullary.id AS nullary_id, nullary.data AS
nullary_data, unary.id AS unary_id, unary.fk AS unary_fk \nFROM
nullary, (SELECT binary.fk1 AS fk1, binary_alias.fk2 AS fk2,
count(*) AS n \nFROM binary JOIN 

[sqlalchemy] Re: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Michael Bayer


On Nov 6, 2007, at 7:03 AM, Esceo wrote:


 the fix? was to add a check for self referential foreign keys in non-
 self-referential relations, and do not add those as part of the
 relation's foreign key collection,

 is this anywhere near the correct thing to do?

possibly. but id prefer not to install arbitrary rules for things that  
shouldn't be done on the outside in the first place, as such rules  
increase the chance of stepping on something that *is* valid.   will  
have to look at this one more closely.

--~--~-~--~~~---~--~~
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: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Michael Bayer

the (child.c.current_id ==child.c.id) part of the parent relation is  
the culprit here, and also its nonsensical.  the relation between  
parent and child is strictly based on the FK between those two  
tables.  additionally its by definition a many-to-one relation; there  
is only one possible Parent that can be attached to the Child so even  
if the additional criterion *did* make sense, its still wouldnt affect  
the outcome.

Ill look into clarifying sqlalchemy's behavior with regards to the  
error message, its getting more confused than it should be with this  
particular scenario.

if youre looking to enhance the child backref part of this, use  
backref=backref('child', **additional_criterion).


On Nov 6, 2007, at 3:42 AM, Esceo wrote:


 Hi, all

 the followings are the code snippet

 from sqlalchemy import *
 meta = MetaData('sqlite://')

 parent = Table('parent', meta,
Column('id', Integer, primary_key=True),
Column('name', Integer)
 )

 child = Table('child', meta,
Column('id', Integer, primary_key=True),
Column('current_id', Integer),
Column('parent_id', Integer),
ForeignKeyConstraint(['parent_id'],['parent.id'],
 ondelete=CASCADE),
ForeignKeyConstraint(['current_id'],['child.id']), )

 class Parent(object):
   pass

 class Child(object):
   pass

 mapper(Parent, parent);

 mapper(Child, child,
properties = { 'parent' : relation(Parent,
primaryjoin =
 (child.c.parent_id == parent.c.id) 
(child.c.current_id ==
 child.c.id),
backref = child),
'current' : relation(Child,
primaryjoin = child.c.current_id ==
 child.c.id)
 })

 meta.create_all()

 s = create_session()
 c = Child()
 c.parent = Parent()
 s.save(c)
 s.flush()
 s.clear()

 running that resulted in

 Traceback (most recent call last):
  File C:\powerforce\test_fk_relation.py, line 39, in module
s.flush()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\session.py, line 320, in flush
self.uow.flush(self, objects)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 210, in flush
flush_context.execute()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 400, in execute
UOWExecutor().execute(self, head)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1018, in execute
self.execute_save_steps(trans, task)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1035, in
 execute_save_steps
self.execute_dependencies(trans, task, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1048, in
 execute_dependencies
self.execute_dependency(trans, dep, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1029, in
 execute_dependency
dep.execute(trans, isdelete)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 984, in execute
self.processor.process_dependencies(self.targettask, [elem.obj for
 elem in self.targettask.polymorphic_tosave_elements if elem.obj is not
 None], trans, delete=False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\dependency.py, line 275, in
 process_dependencies
self._synchronize(obj, child, None, False, uowcommit)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\dependency.py, line 310, in _synchronize
self.syncrules.execute(source, dest, obj, child, clearkeys)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\sync.py, line 92, in execute
rule.execute(source, dest, obj, child, clearkeys)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\sync.py, line 135, in execute
value = self.source_mapper.get_attr_by_column(source,
 self.source_column)
  File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\mapper.py, line 1017, in get_attr_by_column
prop = self._getpropbycolumn(column, raiseerror)
  File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\mapper.py, line 1007, in _getpropbycolumn
raise exceptions.InvalidRequestError(Column '%s.%s' is not
 available, due to conflicting property '%s':%s % (column.table.name,
 column.name, column.key, repr(prop)))
 sqlalchemy.exceptions.InvalidRequestError: Column 'child.id' is not
 available, d
 ue to conflicting property
 'id':sqlalchemy.orm.properties.ColumnProperty object at 0x016FB730

 If I had renamed the id column 

[sqlalchemy] Wrong SQL statement for mapped select involving in_

2007-11-06 Thread klaus

Hi all,
the following mapped select results in the wrong query. The problem
seems to be related to the number of values in a list passed to in_
and maybe to holes in the list of chosen values.


from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData(...)
metadata.bind.echo=True

table = Table(test, metadata,
  Column(id, Integer, primary_key=True),
  Column(data, String))

table.create()

table.insert().execute([{data: 1}, {data: 2}, {data: 3},
{data: 4}, {data: 5}, {data: 6},
{data: 7}, {data: 8}, {data: 9},
{data: 10}, {data: 11}, {data: 12},
{data: 13}, {data: 14}, {data: 15},
{data: 30}, {data: 44}, {data: 55}])

test = table.select(table.c.id.in_([2, 3, 4, 5, 8, 10, 11, 13, 30, 44,
45])).alias(testView)

class Test(object):
pass

mapper(Test, test)

referer = Table(referer, metadata,
Column(id, Integer, primary_key=True),
Column(fk, Integer, ForeignKey(test.id)))

referer.create()

referer.insert().execute([{fk: 2}])

class Referer(object):
pass

mapper(Referer, referer, properties={ref: relation(Test)})

session = create_session()

t = session.query(Test).get(2)
print t
r = session.query(Referer).get(1)
print r.fk, r.ref


It prints

None
2 None

and the SQL statement for the first get should have param_1=1 instead
of None.

2007-11-06 16:26:30,394 INFO sqlalchemy.engine.base.Engine.0x..34
SELECT testView.id AS testView_id, testView.data AS
testView_data
FROM (SELECT test.id AS id, test.data AS data
FROM test
WHERE test.id IN (%(test_id)s, %(test_id_1)s, %(test_id_2)s, %
(test_id_3)s, %(test_id_4)s, %(test_id_5)s, %(test_id_6)s, %
(test_id_7)s, %(test_id_8)s, %(test_id_9)s, %(test_id_10)s)) AS
testView
WHERE testView.id = %(param_1)s ORDER BY testView.id
2007-11-06 16:26:30,394 INFO sqlalchemy.engine.base.Engine.0x..34
{'test_id_3': 5, 'test_id_10': 45, 'param_1': None, 'test_id_8': 30,
'test_id_9': 44, 'test_id_1': 3, 'test_id_2': 4, 'test_id': 2,
'test_id_4': 8, 'test_id_5': 10, 'test_id_6': 11, 'test_id_7': 13}


Best regards
  Klaus


--~--~-~--~~~---~--~~
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: access mapped object attributes

2007-11-06 Thread Christophe Alexandre

Hi,

I am also interested in retrieving all the attributes resulting from the
ORM.

The loop on '.c' will list only the database columns. Is there a way to
list the object attributes?

Thanks a lot for your help,

Chris

-Original Message-
From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of Paul Johnston
Sent: Monday, November 05, 2007 8:45 PM
To: sqlalchemy@googlegroups.com
Subject: [sqlalchemy] Re: access mapped object attributes


Hi,

Given a Message object, do I have a way to retrieve all the attributes
that result from the database mapping? 

Try this:

for col in Message.c:
...

Paul


--~--~-~--~~~---~--~~
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: access mapped object attributes

2007-11-06 Thread Rick Morrison
all of them? same as any Python object:

obj_attributes = [k for k in obj.__dict__]



On 11/6/07, Christophe Alexandre [EMAIL PROTECTED] wrote:


 Hi,

 I am also interested in retrieving all the attributes resulting from the
 ORM.

 The loop on '.c' will list only the database columns. Is there a way to
 list the object attributes?

 Thanks a lot for your help,

 Chris

 -Original Message-
 From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED]
 On Behalf Of Paul Johnston
 Sent: Monday, November 05, 2007 8:45 PM
 To: sqlalchemy@googlegroups.com
 Subject: [sqlalchemy] Re: access mapped object attributes


 Hi,

 Given a Message object, do I have a way to retrieve all the attributes
 that result from the database mapping?
 
 Try this:

 for col in Message.c:
 ...

 Paul


 


--~--~-~--~~~---~--~~
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: access mapped object attributes

2007-11-06 Thread King Simon-NFHD78

You may be interested in an older thread, 'How to get list of
relations':

http://groups.google.com/group/sqlalchemy/browse_thread/thread/ff03af921
eb12acb/861597e8a72f5e6f

Simon 

-Original Message-
From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of Christophe Alexandre
Sent: 06 November 2007 15:59
To: sqlalchemy@googlegroups.com
Subject: [sqlalchemy] Re: access mapped object attributes


Hi,

I am also interested in retrieving all the attributes resulting from the
ORM.

The loop on '.c' will list only the database columns. Is there a way to
list the object attributes?

Thanks a lot for your help,

Chris

-Original Message-
From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of Paul Johnston
Sent: Monday, November 05, 2007 8:45 PM
To: sqlalchemy@googlegroups.com
Subject: [sqlalchemy] Re: access mapped object attributes


Hi,

Given a Message object, do I have a way to retrieve all the attributes
that result from the database mapping? 

Try this:

for col in Message.c:
...

Paul




--~--~-~--~~~---~--~~
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: mapper

2007-11-06 Thread lur ibargutxi

Once i did what you said, I'm trying to insert values to the db:

indg=IndicatorGroups(idindicatorgroup=None, name=group)
session.save(indg)
session.flush()
indsg=IndicatorGroups(idindicatorgroup=None, name=subgroup)
session.save(indsg)
session.flush()

I create two IndicatorGroups but when I want to create a GroupGroups:

groupgroup=GroupGroups(idgroupgroup=None,idindicatorgroupcontainer=indg.idindicatorgroup,
idindicatorgroupcontained=indsg.idindicatorgroup)
session.save(groupgroup)
session.flush()
 I have this problem:

Traceback (innermost last):
  Module ZPublisher.Publish, line 115, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 41, in call_object
  Module Products.odr.lugabe_db.browser.csv_insert, line 26, in __call__
  Module Products.odr.lugabe_db.insert, line 42, in insert
  Module sqlalchemy.orm.attributes, line 1025, in init
  Module Products.odr.lugabe_db.groupgroups, line 18, in __init__
  Module sqlalchemy.orm.attributes, line 32, in __set__
  Module sqlalchemy.orm.attributes, line 363, in set
  Module sqlalchemy.orm.attributes, line 304, in fire_replace_event
AttributeError: 'long' object has no attribute '_state'

2007/11/6, lur ibargutxi [EMAIL PROTECTED]:
 thanks a lot. That's the solution.

 2007/11/6, Marco Mariani [EMAIL PROTECTED]:
 
  lur ibargutxi wrote:
 
  I forgot. Try using tables instead of classes that are not mapped yet..
 
  mappers['groupgroups'] = mapper(GroupGroups, tables['groupgroups'],
  properties = {
 
  'idindicatorgroupcontainer' : relation(IndicatorGroups,
  primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontainer)),'idindicatorgroupcontained'
  : relation(IndicatorGroups,
  primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontained)),
  },allow_column_override=True)
 
 
 
 
   
 


 --
 Lur Ibargutxi
 [EMAIL PROTECTED]



-- 
Lur Ibargutxi
[EMAIL PROTECTED]

--~--~-~--~~~---~--~~
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] data inserted by db trigger is not returned when I re-query the row

2007-11-06 Thread Werner F. Bruhin

I insert a raw into a table and then retrieve again but columns which 
are filled by a db trigger don't return the updated values.

The following is a code snippet and I wonder what I am missing.

engine = sa.create_engine(url, encoding='utf8', echo=False)
Session = sao.sessionmaker(autoflush=True, transactional=True)
Session.configure(bind=engine)
session = Session()
botlot = db.Bottaglot()
session.save(botlot)
session.commit()

print 'org'
print botlot.bottaglotid
print botlot.updated

botlot2 = session.query(db.Bottaglot).get(botlot.bottaglotid)
print 'reloaded'
print botlot2.bottaglotid
print botlot2.updated

Both columns updated will show None instead of at least for botlot2 it 
should show the current date which was inserted into that column by a db 
trigger.

If then run this:
engine = sa.create_engine(url, encoding='utf8', echo=False)
Session = sao.sessionmaker(autoflush=True, transactional=True)
Session.configure(bind=engine)
session = Session()
botlot3 = session.query(db.Bottaglot).get(39)
print 'reloaded'
print botlot3.bottaglotid
print botlot3.updated

At this point I get the value for the column updated I expected.

What am I missing?

Werner

P.S.
This is with SA 0.4 final and Firebird SQL 2.1beta

--~--~-~--~~~---~--~~
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: data inserted by db trigger is not returned when I re-query the row

2007-11-06 Thread Michael Bayer


On Nov 6, 2007, at 12:20 PM, Werner F. Bruhin wrote:


 I insert a raw into a table and then retrieve again but columns which
 are filled by a db trigger don't return the updated values.

 The following is a code snippet and I wonder what I am missing.

 engine = sa.create_engine(url, encoding='utf8', echo=False)
 Session = sao.sessionmaker(autoflush=True, transactional=True)
 Session.configure(bind=engine)
 session = Session()
 botlot = db.Bottaglot()
 session.save(botlot)
 session.commit()

 print 'org'
 print botlot.bottaglotid
 print botlot.updated

 botlot2 = session.query(db.Bottaglot).get(botlot.bottaglotid)
 print 'reloaded'
 print botlot2.bottaglotid
 print botlot2.updated

 Both columns updated will show None instead of at least for  
 botlot2 it
 should show the current date which was inserted into that column by  
 a db
 trigger.


set a PassiveDefault on the triggered column.  that will indicate to  
the mapper that it should post-fetch the value after an insert. note  
that if the trigger is on a primary key column, it wont work since we  
need primary key values in order to post-fetch.


--~--~-~--~~~---~--~~
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] r3695 causes strange error

2007-11-06 Thread sdobrev

hi.
i have somewhat messy setup (~test case), about association with 
intermediate table/class, double pointing to one side and single 
pointing to another. i do set up both A-links in one item; and set up 
only first in another item, the other link (a2_link) is pre-set to None. 
And, i have the error below since r3695.
The error seems to disappear if i do not explicitly initiate the a2_link 
to None - dont touch it or set to some object.
Any idea what's wrong?

Traceback (most recent call last):
  File a.py, line 91, in module
s.flush()
  File /home/az/src/hor-trunk/sqlalchemy/orm/session.py, line 683, in 
flush
self.uow.flush(self, objects)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 209, 
in flush
flush_context.execute()
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 436, 
in execute
UOWExecutor().execute(self, head)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1055, 
in execute
self.execute_save_steps(trans, task)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1074, 
in execute_save_steps
self.execute_childtasks(trans, task, False)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1092, 
in execute_childtasks
self.execute(trans, child, isdelete)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1055, 
in execute
self.execute_save_steps(trans, task)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1072, 
in execute_save_steps
self.execute_dependencies(trans, task, False)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1085, 
in execute_dependencies
self.execute_dependency(trans, dep, False)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1066, 
in execute_dependency
dep.execute(trans, isdelete)
  File /home/az/src/hor-trunk/sqlalchemy/orm/unitofwork.py, line 1021, 
in execute
self.processor.process_dependencies(self.targettask, [elem.obj for 
elem in self.targettask.polymorphic_tosave_elements if elem.obj is not 
None], trans, delete=False)
  File /home/az/src/hor-trunk/sqlalchemy/orm/dependency.py, line 282, 
in process_dependencies
self._synchronize(obj, child, None, False, uowcommit)
  File /home/az/src/hor-trunk/sqlalchemy/orm/dependency.py, line 317, 
in _synchronize
self.syncrules.execute(source, dest, obj, child, clearkeys)
  File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 91, in execute
rule.execute(source, dest, obj, child, clearkeys)
  File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 139, in execute
raise exceptions.AssertionError(Dependency rule tried to blank-out 
primary key column '%s' on instance '%s' % (str(self.dest_column), 
mapperutil.instance_str(dest)))
sqlalchemy.exceptions.AssertionError: Dependency rule tried to blank-out 
primary key column 'IntermediateAB.a2_link_id' on instance 
'[EMAIL PROTECTED]'


--~--~-~--~~~---~--~~
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: r3695 causes strange error

2007-11-06 Thread sdobrev

[EMAIL PROTECTED] wrote:
 sorry, here the files
   
and the line 83 ( marked XXX ) there must be =None to get the error.

--~--~-~--~~~---~--~~
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: Wrong SQL statement for mapped select involving in_

2007-11-06 Thread Michael Bayer

I cant reproduce this one.  I see you have named bind params so I  
tried with postgres.  it also works with sqlite.  works with release  
0.4.0 as well as the trunk.output is (with echoing):

SELECT testView.id AS testView_id, testView.data AS  
testView_data
FROM (SELECT test.id AS id, test.data AS data
FROM test
WHERE test.id IN (%(test_id)s, %(test_id_1)s, %(test_id_2)s, % 
(test_id_3)s, %(test_id_4)s, %(test_id_5)s, %(test_id_6)s, % 
(test_id_7)s, %(test_id_8)s, %(test_id_9)s, %(test_id_10)s)) AS  
testView
WHERE testView.id = %(param_1)s ORDER BY testView.id
2007-11-06 18:57:05,087 INFO sqlalchemy.engine.base.Engine.0x..b0  
{'test_id_3': 5, 'test_id_10': 45, 'param_1': 2, 'test_id_8': 30,  
'test_id_9': 44, 'test_id_1': 3, 'test_id_2': 4, 'test_id': 2,  
'test_id_4': 8, 'test_id_5': 10, 'test_id_6': 11, 'test_id_7': 13}
__main__.Test object at 0xc4e610
2007-11-06 18:57:05,090 INFO sqlalchemy.engine.base.Engine.0x..b0  
SELECT referer.id AS referer_id, referer.fk AS referer_fk
FROM referer
WHERE referer.id = %(param_1)s ORDER BY referer.id
2007-11-06 18:57:05,090 INFO sqlalchemy.engine.base.Engine.0x..b0  
{'param_1': 1}
2 __main__.Test object at 0xc4e610

try coming up with a reproducing test case and reopen ticket #853 if  
you can come up with it.


On Nov 6, 2007, at 10:33 AM, klaus wrote:


 Hi all,
 the following mapped select results in the wrong query. The problem
 seems to be related to the number of values in a list passed to in_
 and maybe to holes in the list of chosen values.


 from sqlalchemy import *
 from sqlalchemy.orm import *

 metadata = MetaData(...)
 metadata.bind.echo=True

 table = Table(test, metadata,
  Column(id, Integer, primary_key=True),
  Column(data, String))

 table.create()

 table.insert().execute([{data: 1}, {data: 2}, {data: 3},
{data: 4}, {data: 5}, {data: 6},
{data: 7}, {data: 8}, {data: 9},
{data: 10}, {data: 11}, {data: 12},
{data: 13}, {data: 14}, {data: 15},
{data: 30}, {data: 44}, {data: 55}])

 test = table.select(table.c.id.in_([2, 3, 4, 5, 8, 10, 11, 13, 30, 44,
 45])).alias(testView)

 class Test(object):
pass

 mapper(Test, test)

 referer = Table(referer, metadata,
Column(id, Integer, primary_key=True),
Column(fk, Integer, ForeignKey(test.id)))

 referer.create()

 referer.insert().execute([{fk: 2}])

 class Referer(object):
pass

 mapper(Referer, referer, properties={ref: relation(Test)})

 session = create_session()

 t = session.query(Test).get(2)
 print t
 r = session.query(Referer).get(1)
 print r.fk, r.ref


 It prints

 None
 2 None

 and the SQL statement for the first get should have param_1=1 instead
 of None.

 2007-11-06 16:26:30,394 INFO sqlalchemy.engine.base.Engine.0x..34
 SELECT testView.id AS testView_id, testView.data AS
 testView_data
 FROM (SELECT test.id AS id, test.data AS data
 FROM test
 WHERE test.id IN (%(test_id)s, %(test_id_1)s, %(test_id_2)s, %
 (test_id_3)s, %(test_id_4)s, %(test_id_5)s, %(test_id_6)s, %
 (test_id_7)s, %(test_id_8)s, %(test_id_9)s, %(test_id_10)s)) AS
 testView
 WHERE testView.id = %(param_1)s ORDER BY testView.id
 2007-11-06 16:26:30,394 INFO sqlalchemy.engine.base.Engine.0x..34
 {'test_id_3': 5, 'test_id_10': 45, 'param_1': None, 'test_id_8': 30,
 'test_id_9': 44, 'test_id_1': 3, 'test_id_2': 4, 'test_id': 2,
 'test_id_4': 8, 'test_id_5': 10, 'test_id_6': 11, 'test_id_7': 13}


 Best regards
  Klaus


 


--~--~-~--~~~---~--~~
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: bug with negative slices in orm.query.Query.__getitem__?

2007-11-06 Thread Michael Bayer

this is how its designed to work at the moment.  if the slices are  
negative, it evaulates the query fully and returns the slice against  
the actual list.   complicating matters more, we just had a feature  
request today to wrap the query in a subquery if additional criterion,  
such as order by, are applied *after* the LIMIT/OFFSET, which would  
make potential solutions (like holding onto the negative-valued slice  
and applying it later at evaluation time) impossible.

On Nov 6, 2007, at 9:27 AM, Simon Wittber wrote:


 Slicing of Query instances can return inconsistent types if negative
 stop/start values are used.

 The below patch to tes/orm/query.py demonstrates the issue. When
 slices with negative stop/start values are used, a list type is
 returned. When positive values are used, a Query instance is returned.
 Is this a bug?

 If this is a bug, I might be able to fix it, but I'm not sure what a
 slice should return. Should a list be returned from a slice operation,
 or should a Query instance be returned?


 Index: orm/query.py
 ===
 --- orm/query.py(revision 3743)
 +++ orm/query.py(working copy)
 @@ -5,6 +5,7 @@
 from sqlalchemy.sql import compiler
 from sqlalchemy.engine import default
 from sqlalchemy.orm import *
 +from sqlalchemy.orm import query
 from testlib import *
 from testlib import engines
 from testlib.fixtures import *
 @@ -268,6 +269,11 @@
 def test_basic(self):
 assert [User(id=7), User(id=8), User(id=9),User(id=10)] ==
 create_session().query(User).all()

 +def test_negative_slices(self):
 +s = create_session()
 +assert type(s.query(Address).filter(Address.user_id==8)[1:3])
 is query.Query
 +assert type(s.query(Address).filter(Address.user_id==8)
 [-2:-1]) is query.Query
 +
 @testing.fails_on('maxdb')
 def test_limit(self):
 assert [User(id=8), User(id=9)] ==
 create_session().query(User).limit(2).offset(1).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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: r3695 causes strange error

2007-11-06 Thread Michael Bayer

ugh can you attach a zipfile please, they came out inline


On Nov 6, 2007, at 5:46 PM, [EMAIL PROTECTED] wrote:

 sorry, here the files

 hi.
 i have somewhat messy setup (~test case), about association with
 intermediate table/class, double pointing to one side and single
 pointing to another. i do set up both A-links in one item; and set up
 only first in another item, the other link (a2_link) is pre-set to  
 None.
 And, i have the error below since r3695.
 The error seems to disappear if i do not explicitly initiate the  
 a2_link
 to None - dont touch it or set to some object.
 Any idea what's wrong?
 ...
  File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 91, in  
 execute
rule.execute(source, dest, obj, child, clearkeys)
  File /home/az/src/dbcook/sqlalchemy/orm/sync.py, line 139, in  
 execute
raise exceptions.AssertionError(Dependency rule tried to blank- 
 out
 primary key column '%s' on instance '%s' % (str(self.dest_column),
 mapperutil.instance_str(dest)))
 sqlalchemy.exceptions.AssertionError: Dependency rule tried to  
 blank-out
 primary key column 'IntermediateAB.a2_link_id' on instance
 '[EMAIL PROTECTED]'



 
 from sa_gentestbase import *
 setup()
 Base.__repr__ = Base.__str__

 #===
 #PYTHONPATH=`pwd`/..:/home/az/src/hor-trunk python mapper/ 
 relation.py -v generate
 #config: db=, debug=, default_lazy=False, echo=False,  
 force_lazy=False, generate=True, log_sa=, lower_pu=True
 #= generated SA set-up

 t = Test_SA( 'setUp' )
 t.setUp()
 meta = t.meta

 table_A = Table( 'A', meta,
Column( 'name', String, ),
Column( 'db_id',   primary_key= True,   type_= Integer, ),
 )
 table_B = Table( 'B', meta,
Column( 'name', String, ),
Column( 'db_id',   primary_key= True,   type_= Integer, ),
 )
 table_IntermediateAB = Table( 'IntermediateAB', meta,
Column( 'color', String, ),
Column( 'a_link_id', Integer, ForeignKey( 'A.db_id', ),
 nullable= False,   primary_key= True, ),
Column( 'a2_link_id', Integer, ForeignKey( 'A.db_id', ),
 nullable= True,   primary_key= True, ),
Column( 'b_boza_id', Integer, ForeignKey( 'B.db_id', ),
 nullable= False,   primary_key= True, ),
 )

 meta.create_all()

 class A( Base):
props = ['db_id', 'name']
 class B( Base):
props = ['db_id', 'name']
 class IntermediateAB( Base):
props = ['db_id', 'color', 'a_link', 'a2_link', 'b_boza']

 mapper_A = mapper( A, table_A,)
 mapper_A.add_property( 'all_ab', relation( IntermediateAB,
#collection_class= bound method type._CollectionFactory  
 of class '__main__.IntermediateAB',
lazy= True,
primaryjoin= table_IntermediateAB.c.a_link_id ==  
 table_A.c.db_id,
remote_side= table_IntermediateAB.c.a_link_id,
uselist= True,
) )

 mapper_B = mapper( B, table_B,)

 mapper_IntermediateAB = mapper( IntermediateAB,  
 table_IntermediateAB, allow_null_pks=True)
 mapper_IntermediateAB.add_property( 'a_link', relation( A,
foreign_keys= table_IntermediateAB.c.a_link_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.a_link_id ==  
 table_A.c.db_id,
remote_side= table_A.c.db_id,
uselist= False,
) )
 mapper_IntermediateAB.add_property( 'a2_link', relation( A,
foreign_keys= table_IntermediateAB.c.a2_link_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.a2_link_id ==  
 table_A.c.db_id,
remote_side= table_A.c.db_id,
uselist= False,
) )
 mapper_IntermediateAB.add_property( 'b_boza', relation( B,
foreign_keys= table_IntermediateAB.c.b_boza_id,
lazy= False,
primaryjoin= table_IntermediateAB.c.b_boza_id ==  
 table_B.c.db_id,
remote_side= table_B.c.db_id,
uselist= False,
) )

 

 #

 a  = A( name= 'a1')
 a3 = A( name= 'a3')
 b1 = B( name= 'b1' )
 b2 = B( name= 'b2' )

 a.all_ab.append( IntermediateAB( b_boza= b1, color='green', a2_link  
 = a3) )
 a.all_ab.append( IntermediateAB( b_boza= b2, color='',
a2_link = a3   #XXX
 ) )

 print '', [i.b_boza for i in a.all_ab]

 s= create_session()
 for z in locals().values():
if isinstance( z, Base): s.save(z)
 s.flush()
 s.clear()

 for t in table_B, table_A, table_IntermediateAB:
print t,':', str( list( t.select().execute() ))

 s= create_session()
 aa = s.query( A ).filter_by(name='a1').first()
 print aa
 print 'xxx'
 l = [i.b_boza for i in aa.all_ab]
 print '', l
 assert len(l) ==2


 #expected output:
 # [B/id=None( name=b1 ), B/id=None( name=b2 )]
 #=== whole database:
 #class '__main__.B' : [(u'b1', 1), (u'b2', 2)]
 #class '__main__.A' : [(None, u'a3', 1), (None, u'a1', 2)]
 #class '__main__.IntermediateAB' : [(None, u'green', 2, 1, 1),  
 (None, u'', 2, None, 2)]
 #A/id=2( name=a1 )
 #xxx
 # [B/id=1( name=b1 ), B/id=2( name=b2 )]
 #$Id: 

[sqlalchemy] Re: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Michael Bayer

I also forgot to mention, the usual workaround here is just to specify  
foreign_keys on the relation() manually.  so this works:

pj = (child.c.parent_id == parent.c.id)  (child.c.current_id  
==child.c.id)
mapper(Child, child,
properties = { 'parent' : relation(Parent,
primaryjoin = pj,
backref = backref(child, primaryjoin=pj,  
foreign_keys=[child.c.parent_id]),
foreign_keys=[child.c.parent_id]
),
'current' : relation(Child,primaryjoin =  
child.c.current_id ==child.c.id)
})


but still, i dont understand the point of the mapping.   youre saying  
that Child has a parent defined by a join against  
child.parent_id==parent.id, *and* the child has its own current  
element set to itself.   so immediately, the operation youre doing in  
the test is wrong:  you create a Child, set its Parent, and its  
current attribute points to nothing, and then you persist it.   
loading that data immediately back from a cleared session will produce  
None for the parent !  observe:

s = create_session()
c = Child()
c.parent = Parent()
s.save(c)
s.flush()
s.clear()

c = s.query(Child).get(c.id)
print c.parent

the final lazy query for c.parent is:

SELECT parent.id AS parent_id, parent.name AS parent_name
FROM parent, child
WHERE ? = parent.id AND child.current_id = child.id ORDER BY parent.oid

and you get:  None .  just as ordered ! note that if you did *not*  
clear the session, no query is issued and then you *do* get the parent  
back.  this is not a bug in SA, this is just your mapping is designed  
to be inconsistent with itself.

So, it seems to me like, instead of having this weird join criterion,  
why not just not set the parent against the child in the first place ?





On Nov 6, 2007, at 5:11 AM, Esceo wrote:


 Just wondering if this is a bug in _determine_fks

 i.e. 'child.id'  probably should not be part of the foreign key
 pointing to parent


 On Nov 6, 7:42 pm, Esceo [EMAIL PROTECTED] wrote:
 Hi, all

 the followings are the code snippet

 from sqlalchemy import *
 meta = MetaData('sqlite://')

 parent = Table('parent', meta,
Column('id', Integer, primary_key=True),
Column('name', Integer)
 )

 child = Table('child', meta,
Column('id', Integer, primary_key=True),
Column('current_id', Integer),
Column('parent_id', Integer),
ForeignKeyConstraint(['parent_id'],['parent.id'],
 ondelete=CASCADE),
ForeignKeyConstraint(['current_id'],['child.id']), )

 class Parent(object):
   pass

 class Child(object):
   pass

 mapper(Parent, parent);

 mapper(Child, child,
properties = { 'parent' : relation(Parent,
primaryjoin =
 (child.c.parent_id == parent.c.id) 
(child.c.current_id ==
 child.c.id),
backref = child),
'current' : relation(Child,
primaryjoin = child.c.current_id ==
 child.c.id)

 })

 meta.create_all()

 s = create_session()
 c = Child()
 c.parent = Parent()
 s.save(c)
 s.flush()
 s.clear()

 running that resulted in

 Traceback (most recent call last):
  File C:\powerforce\test_fk_relation.py, line 39, in module
s.flush()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\session.py, line 320, in flush
self.uow.flush(self, objects)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 210, in flush
flush_context.execute()
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 400, in execute
UOWExecutor().execute(self, head)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1018, in execute
self.execute_save_steps(trans, task)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1035, in
 execute_save_steps
self.execute_dependencies(trans, task, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1048, in
 execute_dependencies
self.execute_dependency(trans, dep, False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1029, in
 execute_dependency
dep.execute(trans, isdelete)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\unitofwork.py, line 984, in execute
self.processor.process_dependencies(self.targettask, [elem.obj for
 elem in self.targettask.polymorphic_tosave_elements if elem.obj is  
 not
 None], trans, delete=False)
  File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
 py2.5.egg\sqlalchemy\orm\dependency.py, line 275, in
 process_dependencies
self._synchronize(obj, child, None, 

[sqlalchemy] Re: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Esceo

Thanks Micahel,

What I intend to model is slightly out of convention here,

The child model has a reference back to the parent, and at the same
time a reference back to the current copy of itself.

On the parent's end, it's only supposed to pick up the current copy,
therefore the additional constraint. (it's not meant to be part of the
foreign key between the parent and child)

Like you said, I am slightly cautious about whether it was the right
thing to do in every case.

On Nov 7, 2:23 am, Michael Bayer [EMAIL PROTECTED] wrote:
 the (child.c.current_id ==child.c.id) part of the parent relation is  
 the culprit here, and also its nonsensical.  the relation between  
 parent and child is strictly based on the FK between those two  
 tables.  additionally its by definition a many-to-one relation; there  
 is only one possible Parent that can be attached to the Child so even  
 if the additional criterion *did* make sense, its still wouldnt affect  
 the outcome.

 Ill look into clarifying sqlalchemy's behavior with regards to the  
 error message, its getting more confused than it should be with this  
 particular scenario.

 if youre looking to enhance the child backref part of this, use  
 backref=backref('child', **additional_criterion).

 On Nov 6, 2007, at 3:42 AM, Esceo wrote:





  Hi, all

  the followings are the code snippet

  from sqlalchemy import *
  meta = MetaData('sqlite://')

  parent = Table('parent', meta,
 Column('id', Integer, primary_key=True),
 Column('name', Integer)
  )

  child = Table('child', meta,
 Column('id', Integer, primary_key=True),
 Column('current_id', Integer),
 Column('parent_id', Integer),
 ForeignKeyConstraint(['parent_id'],['parent.id'],
  ondelete=CASCADE),
 ForeignKeyConstraint(['current_id'],['child.id']), )

  class Parent(object):
pass

  class Child(object):
pass

  mapper(Parent, parent);

  mapper(Child, child,
 properties = { 'parent' : relation(Parent,
 primaryjoin =
  (child.c.parent_id == parent.c.id) 
 (child.c.current_id ==
  child.c.id),
 backref = child),
 'current' : relation(Child,
 primaryjoin = child.c.current_id ==
  child.c.id)
  })

  meta.create_all()

  s = create_session()
  c = Child()
  c.parent = Parent()
  s.save(c)
  s.flush()
  s.clear()

  running that resulted in

  Traceback (most recent call last):
   File C:\powerforce\test_fk_relation.py, line 39, in module
 s.flush()
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\session.py, line 320, in flush
 self.uow.flush(self, objects)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 210, in flush
 flush_context.execute()
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 400, in execute
 UOWExecutor().execute(self, head)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1018, in execute
 self.execute_save_steps(trans, task)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1035, in
  execute_save_steps
 self.execute_dependencies(trans, task, False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1048, in
  execute_dependencies
 self.execute_dependency(trans, dep, False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 1029, in
  execute_dependency
 dep.execute(trans, isdelete)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\unitofwork.py, line 984, in execute
 self.processor.process_dependencies(self.targettask, [elem.obj for
  elem in self.targettask.polymorphic_tosave_elements if elem.obj is not
  None], trans, delete=False)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\dependency.py, line 275, in
  process_dependencies
 self._synchronize(obj, child, None, False, uowcommit)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\dependency.py, line 310, in _synchronize
 self.syncrules.execute(source, dest, obj, child, clearkeys)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\sync.py, line 92, in execute
 rule.execute(source, dest, obj, child, clearkeys)
   File C:\Python25\lib\site-packages\sqlalchemy-0.3.11dev_r3181-
  py2.5.egg\sqlalchemy\orm\sync.py, line 135, in execute
 value = self.source_mapper.get_attr_by_column(source,
  self.source_column)
   File C:\Python25\lib\site-packages\SQLAlchemy-0.3.11dev_r3181-
  

[sqlalchemy] Re: A Query object seems to be altered by a count() - is this a bug?

2007-11-06 Thread Michael Bayer

indeed its extremely difficult to reproduce this one, and while it was  
pretty clear what caused it i found it impossible to work up a simpler  
set of tables that could create all the conditions necessary to  
produce an invalid query...in any case the offending code was some  
stuff that wasnt even needed so its removed in r3746.


On Nov 6, 2007, at 9:40 AM, klaus wrote:


 Hi all,
 when I try to build up a complicated query like this:

 query = session.query(Class)
 query = query.filter_by(...).add_entity(...).join(...)
 count = query.count()
 query = query.add_entity(...).join(...).order_by(...)
 print query.all()

 the last statement fails due to a broken SELECT. The error disappears
 if I remove the line with the query.count().

 The following is an example to reproduce the behavior. I'm sorry that
 it is so complicated, but a certain complexity seems to be necessary
 to trigger the bug.


 


--~--~-~--~~~---~--~~
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: r3695 causes strange error

2007-11-06 Thread Michael Bayer

nevermind, this one was pretty straightforward and r3695 didnt  
actually break things, it just revealed the lack of checking for  
things elsewhere, so works in r3747.

On Nov 6, 2007, at 5:50 PM, [EMAIL PROTECTED] wrote:


 [EMAIL PROTECTED] wrote:
 sorry, here the files

 and the line 83 ( marked XXX ) there must be =None to get the error.

 


--~--~-~--~~~---~--~~
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: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Michael Bayer


On Nov 6, 2007, at 8:24 PM, Esceo wrote:


 Thanks Micahel,

 What I intend to model is slightly out of convention here,

 The child model has a reference back to the parent, and at the same
 time a reference back to the current copy of itself.

 On the parent's end, it's only supposed to pick up the current copy,
 therefore the additional constraint. (it's not meant to be part of the
 foreign key between the parent and child)

 Like you said, I am slightly cautious about whether it was the right
 thing to do in every case.

well you can leave it as is and have the inconsistent behavior,  
which is dangerous since how the object got into the session affects  
the outcome, or just map an additional most_recent_parent or similar  
relation with viewonly=True representing that particular view.


--~--~-~--~~~---~--~~
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: How do we configure additional primary join constrains that seemingly involes other relations

2007-11-06 Thread Esceo

What I am slightly unsure about is how the viewonly flag affect the
unit of work process.

If i have acquired most_recent_child through parent, and made change
to it, will they be saved as part of uow process? (guess I should just
do a test)

Lei

On Nov 7, 12:43 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Nov 6, 2007, at 8:24 PM, Esceo wrote:



  Thanks Micahel,

  What I intend to model is slightly out of convention here,

  The child model has a reference back to the parent, and at the same
  time a reference back to the current copy of itself.

  On the parent's end, it's only supposed to pick up the current copy,
  therefore the additional constraint. (it's not meant to be part of the
  foreign key between the parent and child)

  Like you said, I am slightly cautious about whether it was the right
  thing to do in every case.

 well you can leave it as is and have the inconsistent behavior,  
 which is dangerous since how the object got into the session affects  
 the outcome, or just map an additional most_recent_parent or similar  
 relation with viewonly=True representing that particular view.


--~--~-~--~~~---~--~~
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] How does auto-reconnect work?

2007-11-06 Thread Hong Yuan

Hi,

In the release note of 0.3.7, the following is mentioned:

- much improved auto-reconnect support

But how can one configure this? I am using 0.3.10 with Postgresql.
Very often, after some period of inactivity, the connection is closed
and the whole application has to be closed and restarted for the
database connection to work again.

How is auto-reconnect suppposed to work? Is there any connection
parameter to alter for instance?

Thanks,

Hong Yuan


--~--~-~--~~~---~--~~
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] Select entire column

2007-11-06 Thread JamesT

I am looking to filter specific columns in a table, but I cannot find
how to do this. I can filter by setting these columns to a value, but
not just grabbing the entire column. In SQL, I want to do this:
SELECT artist FROM artist_table, where the only column kept is
artist. The reason I want to do this is so that I can run a distinct()
on the Query object returned to get the distinct artists and also
distinct genres. Here is a sample of what I am doing now without
filtering to get the data I need:

tuples = Session.query(Albums).add_entity(Songs).join('songs').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?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: r3695 causes strange error

2007-11-06 Thread sdobrev

Michael Bayer wrote:
 nevermind, this one was pretty straightforward and r3695 didnt  
 actually break things, it just revealed the lack of checking for  
 things elsewhere, so works in r3747.
   
yes, that works.
but now multiple other things broke. pf

 - the mapper.properties in its new get()/iterate() form is not 
available yet when mapper-extensions are setup (e.g. at 
ext.instrument_class). i need to find which attribute-name is being 
mapped to certain table.column... maybe i can get without it..

 - something changed in the traversing (AbstractClauseProcessor - r3727) 
and it does not find proper things...

 - r3735 - i started getting again these:
 File /home/az/src/dbcook/sqlalchemy/orm/util.py, line 261, in __getitem__
return self.row[key]
  File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1247, in 
__getitem__
return self.__parent._get_col(self.__row, key)
  File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1470, in 
_get_col
rec = self._key_cache[key]
  File /home/az/src/dbcook/sqlalchemy/util.py, line 72, in __missing__
self[key] = val = self.creator(key)
  File /home/az/src/dbcook/sqlalchemy/engine/base.py, line 1375, in 
lookup_key
raise exceptions.NoSuchColumnError(Could not locate column in row 
for column '%s' % (str(key)))
NoSuchColumnError: Could not locate column in row for column 'A_tbl.db_id'

details later.


--~--~-~--~~~---~--~~
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: mapper

2007-11-06 Thread lur ibargutxi

2007/11/6, lur ibargutxi [EMAIL PROTECTED]:
 Once i did what you said, I'm trying to insert values to the db:

 indg=IndicatorGroups(idindicatorgroup=None, name=group)
 session.save(indg)
 session.flush()
 indsg=IndicatorGroups(idindicatorgroup=None, name=subgroup)
 session.save(indsg)
 session.flush()

 I create two IndicatorGroups but when I want to create a GroupGroups:

 groupgroup=GroupGroups(idgroupgroup=None,idindicatorgroupcontainer=indg.idindicatorgroup,
 idindicatorgroupcontained=indsg.idindicatorgroup)

I think this is wrong and I have to do like this:
groupgroup=GroupGroups(idgroupgroup=None,idindicatorgroupcontainer=indg,
idindicatorgroupcontained=indsg)
but now the error is the next one:
Traceback (innermost last):
  Module ZPublisher.Publish, line 115, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 41, in call_object
  Module Products.odr.lugabe_db.browser.csv_insert, line 26, in __call__
  Module Products.odr.lugabe_db.insert, line 44, in insert
  Module sqlalchemy.orm.session, line 681, in flush
  Module sqlalchemy.orm.unitofwork, line 216, in flush
  Module sqlalchemy.orm.unitofwork, line 432, in execute
  Module sqlalchemy.orm.unitofwork, line 1051, in execute
  Module sqlalchemy.orm.unitofwork, line 1068, in execute_save_steps
  Module sqlalchemy.orm.unitofwork, line 1081, in execute_dependencies
  Module sqlalchemy.orm.unitofwork, line 1062, in execute_dependency
  Module sqlalchemy.orm.unitofwork, line 1017, in execute
  Module sqlalchemy.orm.dependency, line 282, in process_dependencies
  Module sqlalchemy.orm.dependency, line 317, in _synchronize
  Module sqlalchemy.orm.sync, line 91, in execute
  Module sqlalchemy.orm.sync, line 143, in execute
  Module sqlalchemy.orm.mapper, line 936, in set_attr_by_column
  Module sqlalchemy.orm.util, line 101, in __getitem__
KeyError: Column(u'idindicatorgroupcontained', MSInteger(length=11),
ForeignKey(u'indicatorgroups.idindicatorgroup'), nullable=False,
default=PassiveDefault(u'0'))

Someone knows how can I fix this?
Thanks a lot

 session.save(groupgroup)
 session.flush()
  I have this problem:

 Traceback (innermost last):
   Module ZPublisher.Publish, line 115, in publish
   Module ZPublisher.mapply, line 88, in mapply
   Module ZPublisher.Publish, line 41, in call_object
   Module Products.odr.lugabe_db.browser.csv_insert, line 26, in __call__
   Module Products.odr.lugabe_db.insert, line 42, in insert
   Module sqlalchemy.orm.attributes, line 1025, in init
   Module Products.odr.lugabe_db.groupgroups, line 18, in __init__
   Module sqlalchemy.orm.attributes, line 32, in __set__
   Module sqlalchemy.orm.attributes, line 363, in set
   Module sqlalchemy.orm.attributes, line 304, in fire_replace_event
 AttributeError: 'long' object has no attribute '_state'

 2007/11/6, lur ibargutxi [EMAIL PROTECTED]:
  thanks a lot. That's the solution.
 
  2007/11/6, Marco Mariani [EMAIL PROTECTED]:
  
   lur ibargutxi wrote:
  
   I forgot. Try using tables instead of classes that are not mapped yet..
  
   mappers['groupgroups'] = mapper(GroupGroups, tables['groupgroups'],
   properties = {
  
   'idindicatorgroupcontainer' : relation(IndicatorGroups,
   primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontainer)),'idindicatorgroupcontained'
   : relation(IndicatorGroups,
   primaryjoin=sql.and_(tables['indicatorgroups'].c.idindicatorgroup==tables['groupgroups'].c.idindicatorgroupcontained)),
   },allow_column_override=True)
  
  
  
  
 
  
 
 
  --
  Lur Ibargutxi
  [EMAIL PROTECTED]
 


 --
 Lur Ibargutxi
 [EMAIL PROTECTED]



-- 
Lur Ibargutxi
[EMAIL PROTECTED]

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