[sqlalchemy] Re: Problem with "SAWarning: Multiple rows returned with uselist=False"

2011-04-08 Thread Aleksander Siewierski
Thanks for response,

TaskIntro table is defined as:

Table(
'task_intros',
METADATA,

Column('id', Integer, primary_key=True),
...
Column('redirect_rule_id', Integer,
ForeignKey('redirect_rules.id'), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8'
)


and query defined in function above is taken as
SESSION.query(TaskIntro) and then I just call method all().

So, from table definition and redirect_rule_id foreign key you can
see, that this is impossible that more than one redirect_rule row will
be matched to task_intro.

Cheers!,
Alex

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Problem with "SAWarning: Multiple rows returned with uselist=False"

2011-04-07 Thread Aleksander Siewierski

Hi, in part of my model I have a TaskIntro item and RedirectRule item
connected with relation one-to-one one-sided, mapper for TaskIntro
looks like:

mapper(
TaskIntro,
table,
version_id_col = table.c.version ,
properties={
 ...
'redirect_rule': relation( RedirectRule,
 cascade="all, delete",
 primaryjoin=table.c.redirect_rule_id ==
redirect_rule_t.c.id
 ),
...
}

and when I call method that get TaskIntro defined:
def _get_all_query(self, **kwargs):
query = self.query.options(
contains_eager('redirect_rule'),
eagerload_all('redirect_rule.periods'),
eagerload('redirect_rule.channels'),
...
)
return query

I receive following warning:
/usr/lib/python2.6/dist-packages/sqlalchemy/orm/mapper.py:2113:
SAWarning: Multiple rows returned with uselist=False for eagerly-
loaded attribute 'TaskIntro.redirect_rule'
  populator(state, dict_, row)

I'm googling about this warning, but have no idea what this can mean.
How can multiple rows be returned here?

What is interesting, this following warning appears in SQLAlchemy
0.6.3-2, but on earlier version doesn't.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Problem with CircularDependencyError

2010-01-28 Thread Aleksander Siewierski
Hi!,

I have two entities: Channel and Track. Track has a reference to
Channel (channel field - Track is played on this Channel), and Channel
has a reference to Track (last_track field - last planned Track for
Channel). So definition of tables, classes and mappers is:

"""
import sqlalchemy
from sqlalchemy.orm import *
from sqlalchemy.schema import *
from sqlalchemy.types import *

sqlalchemy_config = {
 'url' : 'mysql://...',
 'echo': True,
 'pool_recycle': 600,
 'convert_unicode' : True,
}

ENGINE = sqlalchemy.engine.engine_from_config(sqlalchemy_config, '')
METADATA = sqlalchemy.schema.MetaData()
METADATA.bind = ENGINE
session_maker = sqlalchemy.orm.sessionmaker(autoflush=True,
transactional=True, bind=ENGINE)
SESSION = sqlalchemy.orm.scoped_session(session_maker)

class Channel(object):
def __init__(self, name):
self.name = name

class Track(object):
def __init__(self, title):
self.title = title

channel_t = Table(
'channels',
METADATA,
Column('id', Integer, primary_key=True),
Column('name', Unicode(256)),
Column('last_track_id', Integer, ForeignKey('tracks.id')),
mysql_engine='InnoDB',
mysql_charset='utf8'
)

track_t = Table(
'tracks',
METADATA,
Column('id', Integer, primary_key=True),
Column('channel_id', Integer, ForeignKey('channels.id'),
nullable=False),
Column('title', Unicode(256)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)

mapper(Channel, channel_t, properties = {
   'last_track': relation(Track,
primaryjoin=channel_t.c.last_track_id == track_t.c.id),
   }
)

mapper(Track, track_t, properties={
   'channel': relation(Channel,
primaryjoin=track_t.c.channel_id == channel_t.c.id),
   }
)

channel1 = SESSION.query(Channel).get(1)
track1 = Track('Track 1')
track1.channel = channel1
channel1.last_track = track1

SESSION.add(track1)
SESSION.commit()
"""

and when I try to commit this, I have following error:
Traceback (most recent call last):
  File "cml.py", line 75, in 
SESSION.commit()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/scoping.py", line 127, in do
return getattr(self.registry(), name)(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/session.py", line 671, in commit
self.transaction.commit()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/session.py", line 378, in commit
self._prepare_impl()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/session.py", line 362, in _prepare_impl
self.session.flush()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/session.py", line 1354, in flush
self._flush(objects)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/session.py", line 1432, in _flush
flush_context.execute()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/unitofwork.py", line 258, in execute
tasks = self._sort_dependencies()
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/unitofwork.py", line 299, in
_sort_dependencies
for t in task._sort_circular_dependencies(self,
[self.get_task_by_mapper(i) for i in cycles]):
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/orm/unitofwork.py", line 582, in
_sort_circular_dependencies
head = topological.sort_as_tree(tuples,
object_to_original_task.iterkeys())
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/topological.py", line 59, in sort_as_tree
return _organize_as_tree(_sort(tuples, allitems,
allow_cycles=with_cycles))
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.5.8-
py2.6.egg/sqlalchemy/topological.py", line 209, in _sort
raise CircularDependencyError("Circular dependency detected " +
repr(edges) + repr(queue))
sqlalchemy.exc.CircularDependencyError: Circular dependency detected
[(,
),
(,
)][]

what is wrong with this definitions? Documentation says that
CircularDependencyError should appear only when I do topological
sorting.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.