pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

Synonyms not identified #106

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Have a table mapping with property like this:
    'date':orm.synonym('_date', map_column=True)
2. item = formalchemy.forms.FieldSet(model.Item)

This barfs:
  File "/home/dread/hgroot/pdw/pyenv/src/formalchemy/formalchemy/forms.py",
line 169, in __init__
    AbstractFieldSet.__init__(self, *args, **kwargs)
  File "/home/dread/hgroot/pdw/pyenv/src/formalchemy/formalchemy/forms.py",
line 50, in __init__
    base.EditableRenderer.__init__(self, *args, **kwargs)
  File "/home/dread/hgroot/pdw/pyenv/src/formalchemy/formalchemy/base.py",
line 176, in __init__
    L = [fields.AttributeField(attr, self) for attr in attrs]
  File
"/home/dread/hgroot/pdw/pyenv/src/formalchemy/formalchemy/fields.py", line
1094, in __init__
    self._property = instrumented_attribute.property
  File
"/home/dread/hgroot/pdw/pyenv/lib/python2.6/site-packages/SQLAlchemy-0.4.8-py2.6
.egg/sqlalchemy/orm/attributes.py",
line 153, in __getattr__
    return getattr(descriptor, attribute)
AttributeError: 'property' object has no attribute 'property'

What version of the product are you using? On what operating system?
1.2 on linux

Please provide any additional information below.

I solved this on my machine with this patch to base.py:

diff -r 56e8e78c4294 formalchemy/base.py
--- a/formalchemy/base.py   Fri Jul 03 22:46:38 2009 +0200
+++ b/formalchemy/base.py   Wed Jul 08 16:41:01 2009 +0100
@@ -169,7 +169,7 @@
             attrs = []
             for p in class_mapper(cls).iterate_properties:
                 attr = _get_attribute(cls, p)
-                if ((isinstance(p, SynonymProperty) or attr.property.key
not in (s.name for s in synonyms))
+                if ((not isinstance(p, SynonymProperty) and
attr.property.key not in (s.name for s in synonyms))
                     and not isinstance(attr.impl, DynamicAttributeImpl)):
                     attrs.append(attr)
             # sort relations last before storing in the OrderedDict

Original issue reported on code.google.com by d.t.r...@gmail.com on 8 Jul 2009 at 3:41

GoogleCodeExporter commented 9 years ago
Unfortunately your change break tests.

File "/Users/gawel/py/formalchemy/formalchemy/tests/test_fieldset.py", line 
1071, in
formalchemy.tests.test_fieldset
Failed example:
    fs_s._fields
Expected:
    {'foo': AttributeField(foo), 'id': AttributeField(id)}
Got:
    {'_foo': AttributeField(_foo), 'id': AttributeField(id)}

I guess the real problem came from the map_column parameters. We don't have 
this in 
tests. Need to add one for this.

Original comment by gael.pas...@gmail.com on 18 Aug 2009 at 10:38

GoogleCodeExporter commented 9 years ago
This is still an issue I take it?

Original comment by kkin...@gmail.com on 23 Jul 2010 at 5:18

GoogleCodeExporter commented 9 years ago
Feel free to fork. But please, don't forget unit tests.

Original comment by gael.pas...@gmail.com on 23 Jul 2010 at 8:02