[Sqlalchemy-tickets] [sqlalchemy] #2808: AssociationProxy should use keywords on create
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-08-21 11:42:29
|
#2808: AssociationProxy should use keywords on create
----------------------+----------------------------------------
Reporter: schlamar | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone: 0.8.xx
Component: ext | Severity: trivial - <10 minutes
Keywords: | Progress State: awaiting triage
----------------------+----------------------------------------
I want to use the Association Object pattern as described in the docs
(http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/associationproxy.html
#simplifying-association-objects). But I do not want to explicitly write a
constructor and rely on the new "every attribute can be passed as kwarg"
style.
This is currently broken with associationproxy, because it passes the
proxied value directly to the constructor. So if the Association Object
has no explicit constructor, the code fails:
{{{
Traceback (most recent call last):
File "d:\Projekte\HACS\tests\test_model.py", line 12, in test_prog_order
job.programs.append(j1)
File
"d:\Projekte\HACS\hacs\packages\sqlalchemy\ext\associationproxy.py", line
567, in append
item = self._create(value)
File
"d:\Projekte\HACS\hacs\packages\sqlalchemy\ext\associationproxy.py", line
494, in _create
return self.creator(value)
TypeError: __init__() takes exactly 1 argument (2 given)
}}}
Fix for me was to patch `_AssociationList._create` with the following, but
maybe I'm missing something.
{{{
def _create(self, value):
return self.creator(**{self.parent.value_attr: value})
}}}
If it looks good to you, I'll send a PR on GitHub to the 0.8 branch.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2808>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|