Hi,

I have a little problem and can't get my head what's happening so any
advice is welcome.
I define the two table following table in my model :

articles_table = Table('articles', metadata,
    Column('article_id', Integer, primary_key=True),
    Column('author', Integer, ForeignKey('tg_user.user_id')),
    Column('content', Unicode),
)

posts_table = Table('posts', metadata,
    Column('post_id', Integer, primary_key=True),
    Column('author', Integer, ForeignKey('tg_user.user_id')),
    Column('title', Unicode(255)),
    Column('content', Unicode, nullable=False),
    Column('article_id', Integer, ForeignKey('article.article_id'),
primary_key=True)
)

If I define the following mappings :

assign_mapper(session.context, Post, posts_table)
assign_mapper(session.context, Article, articles_table,
    properties = {'comments':relation(Post)}
)

I get this error when trying to start the project, at first DB
operation processed :

  File "build/bdist.linux-x86_64/egg/sqlalchemy/util.py", line 205, in
__getattr__
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/mapper.py", line
241, in _get_data
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/mapper.py", line
321, in compile
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/mapper.py", line
341, in _compile_all
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/mapper.py", line
596, in _initialize_properties
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/interfaces.py",
line 60, in init
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/properties.py",
line 183, in do_init
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/properties.py",
line 240, in _determine_joins
sqlalchemy.exceptions.ArgumentError: Error determining primary and/or
secondary join for relationship 'Article.comments (Post)'. If the
underlying error cannot be corrected, you should specify the
'primaryjoin' (and 'secondaryjoin', if there is an association table
present) keyword arguments to the relation() function (or for
backrefs, by specifying the backref using the backref() function with
keyword arguments) to explicitly specify the join conditions. Nested
error is "Table 'None.article' not defined"

So I have dropped the property :

assign_mapper(session.context, Post, posts_table)
assign_mapper(session.context, Article, articles_table,
    #properties = {'comments':relation(Post)}
)

Everything seems to work fine until I try to use both in a function of
my controller

class CommentsController(controllers.Controller):

    @expose(template=".templates.comments.commentArticle")
    def verify(self, id, tg_errors=None, **kw):
        comment = Post()
        comment.post_id = sa.select([sa.func.count(comment.c.post_id)
+1],
                                    comment.c.article_id == id
                                   ).execute().fetchone()[0]
        comment.article_id = id
        comment.author = identity.current.user.user_id
        comment.title = kw['title']
        comment.content = kw['comment']
        comment.save_or_update()
        # Get Article
        article = session.get(Article, id)
        return dict(article=article, comment=comment)

The function execute ok but before rendering TG tries to automagically
flush things (I guess)
and it fails with the following error :

2007-07-20 21:54:08,261 betta.subcontrollers.news DEBUG
**********************************************
2007-07-20 21:54:08,261 betta.subcontrollers.news DEBUG
**********************************************
2007-07-20 21:54:08,261 betta.subcontrollers.news DEBUG *** Now we
return the function : ***
2007-07-20 21:54:08,261 betta.subcontrollers.news DEBUG *** Now we
return the function : ***
2007-07-20 21:54:08,367 INFO sqlalchemy.engine.base.Engine.0x..74
SELECT tg_group.display_name AS tg_group_display_name,
tg_group.created AS tg_group_created, tg_group.group_name AS
tg_group_group_name, tg_group.group_id AS tg_group_group_id
FROM tg_group, user_group
WHERE %(lazy_efe)s = user_group.user_id AND tg_group.group_id =
user_group.group_id
2007-07-20 21:54:08,367 sqlalchemy.engine.base.Engine.0x..74 INFO
SELECT tg_group.display_name AS tg_group_display_name,
tg_group.created AS tg_group_created, tg_group.group_name AS
tg_group_group_name, tg_group.group_id AS tg_group_group_id
FROM tg_group, user_group
WHERE %(lazy_efe)s = user_group.user_id AND tg_group.group_id =
user_group.group_id
2007-07-20 21:54:08,367 INFO sqlalchemy.engine.base.Engine.0x..74
{'lazy_efe': 0}
2007-07-20 21:54:08,367 sqlalchemy.engine.base.Engine.0x..74 INFO
{'lazy_efe': 0}
2007-07-20 21:54:08,391 INFO sqlalchemy.engine.base.Engine.0x..74
ROLLBACK
2007-07-20 21:54:08,391 sqlalchemy.engine.base.Engine.0x..74 INFO
ROLLBACK
2007-07-20 21:54:08,411 cherrypy.msg INFO HTTP: Page handler: <bound
method CommentsController.verify of
<betta.subcontrollers.comments.CommentsController object at
0xf72b142c>>
Traceback (most recent call last):
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py",
line 105, in _run
    self.main()
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py",
line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in verify
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/
turbogears/controllers.py", line 334, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/
turbogears/database.py", line 354, in sa_rwt
    retval = dispatch_exception(e,args,kw)
  File "/usr/lib/python2.4/site-packages/TurboGears-1.0.2.2-py2.4.egg/
turbogears/database.py", line 344, in sa_rwt
    req.sa_transaction.commit()
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line
62, in commit
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line
302, in flush
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py",
line 210, in flush
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py",
line 400, in execute
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py",
line 1018, in execute
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py",
line 1032, in execute_save_steps
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py",
line 1023, in save_objects
  File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/mapper.py", line
1062, in save_obj
  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql_util.py", line 33,
in sort
  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql_util.py", line 54,
in _do_sort
  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql.py", line 877, in
traverse
  File "build/bdist.linux-x86_64/egg/sqlalchemy/schema.py", line 731,
in accept_visitor
  File "build/bdist.linux-x86_64/egg/sqlalchemy/sql_util.py", line 48,
in visit_foreign_key
  File "build/bdist.linux-x86_64/egg/sqlalchemy/schema.py", line 726,
in <lambda>
  File "build/bdist.linux-x86_64/egg/sqlalchemy/schema.py", line 707,
in _init_column
  File "build/bdist.linux-x86_64/egg/sqlalchemy/schema.py", line 155,
in __call__
ArgumentError: Table 'None.article' not defined


SQLAlchemy version is 0.3.8

$ tg-admin info
TurboGears Complete Version Information

TurboGears requires:

* TurboGears 1.0.2.2
* cElementTree 1.0.5-20051216
* configobj 4.4.0
* DecoratorTools 1.4
* RuleDispatch 0.5a0.dev-r2306
* setuptools 0.6c5
* FormEncode 0.7.1
* PasteScript 1.3.5
* elementtree 1.2.6-20050316
* simplejson 1.7.1
* CherryPy 2.2.1
* TurboKid 1.0.1
* TurboCheetah 0.9.5
* TurboJson 1.0
* PyProtocols 1.0a0dev-r2302
* PasteDeploy 1.3.1
* Paste 1.4
* kid 0.9.5
* Cheetah 2.0rc7
* RuleDispatch 0.5a0.dev-r2306
* DecoratorTools 1.4

Identity Providers

* sqlobject (TurboGears 1.0.2.2)
* sqlalchemy (TurboGears 1.0.2.2)

tg-admin Commands

* info (TurboGears 1.0.2.2)
* shell (TurboGears 1.0.2.2)
* quickstart (TurboGears 1.0.2.2)
* update (TurboGears 1.0.2.2)
* sql (TurboGears 1.0.2.2)
* i18n (TurboGears 1.0.2.2)
* toolbox (TurboGears 1.0.2.2)

Visit Managers

* sqlobject (TurboGears 1.0.2.2)
* sqlalchemy (TurboGears 1.0.2.2)

Template Engines

* kid (TurboKid 1.0.1)
* cheetah (TurboCheetah 0.9.5)
* genshi-markup (Genshi 0.4.2)
* genshi-text (Genshi 0.4.2)
* genshi (Genshi 0.4.2)
* json (TurboJson 1.0)

Widget Packages

* scriptaculous (Scriptaculous 1.6.2)
* lightbox (Lightbox 2.0-p1)
* fckeditor (TurboFCKeditor 0.1)

Toolbox Plugins

* info (TurboGears 1.0.2.2)
* catwalk (TurboGears 1.0.2.2)
* shell (TurboGears 1.0.2.2)
* designer (TurboGears 1.0.2.2)
* widgets (TurboGears 1.0.2.2)
* admi18n (TurboGears 1.0.2.2)

TurboGears Extensions

* turbomail (TurboMail 2.0.3)
* visit (TurboGears 1.0.2.2)
* identity (TurboGears 1.0.2.2)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to