pombreda / formalchemy

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

Cannot render NUMERIC type with Postgres database #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a table in PostgreSQL with a NUMERIC field type:

create table test(
  id serial primary key,
  item numeric
);

2. Reflect and map that table to an object (see attached file for test).

3. Try to render the class as a FieldSet.

What is the expected output? What do you see instead?

Expected is HTML for the form.  Instead I get an exception: TypeError: No
renderer found for field item. Type PGNumeric(precision=None, scale=None,
asdecimal=True, length=None) as no default renderer at line 11 column 3 in
file fieldset_template

Full stack trace below:

Traceback (most recent call last):
  File "/home/ratchet/src/wztest/<string>", line 1, in <module>
  File "/home/ratchet/src/wztest/bug_test.py", line 25, in <module>
    print form.render()
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/forms.py",
line 305, in render
    return self._render(fieldset=self, **kwargs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 154, in substitute
    result, defs, inherit = self._interpret(ns)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 165, in _interpret
    self._interpret_codes(self._parsed, ns, out=parts, defs=defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 193, in _interpret_codes
    self._interpret_code(item, ns, out, defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 207, in _interpret_code
    self._interpret_for(vars, expr, content, ns, out, defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 255, in _interpret_for
    self._interpret_codes(content, ns, out, defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 193, in _interpret_codes
    self._interpret_code(item, ns, out, defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 210, in _interpret_code
    self._interpret_if(parts, ns, out, defs)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 266, in _interpret_if
    result = self._eval(part[2], ns, pos)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/tempita/__init__.py",
line 288, in _eval
    value = eval(code, ns)
  File "/home/ratchet/src/wztest/<string>", line 1, in <module>
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/fields.py",
line 592, in requires_label
    return not isinstance(self.renderer, HiddenFieldRenderer)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/fields.py",
line 762, in renderer
    self._renderer = self._get_renderer()
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/fields.py",
line 1069, in _get_renderer
    return AbstractField._get_renderer(self)
  File
"/home/ratchet/src/wz/lib/python2.5/site-packages/FormAlchemy-1.1-py2.5.egg/form
alchemy/fields.py",
line 758, in _get_renderer
    'Type %s as no default renderer' % (self.name, self.type))
TypeError: No renderer found for field item. Type PGNumeric(precision=None,
scale=None, asdecimal=True, length=None) as no default renderer at line 11
column 3 in file fieldset_template

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

Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22) 
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]

using SQLAlchemy 0.5.0rc4 and FormAlchemy 1.1

Original issue reported on code.google.com by foxp...@gmail.com on 23 Dec 2008 at 4:38

Attachments:

GoogleCodeExporter commented 9 years ago
can this be generalized to missing support for sqlalchemy.types.Numeric?

Using FloatFieldRenderer seems reasonable for rendering. I wonder how the
deserializing should work, though.

Original comment by monkeylo...@gmail.com on 28 Dec 2008 at 6:25

GoogleCodeExporter commented 9 years ago
this patch adds support for sqlalchemy.types.Numeric and some tests for that 
support.
Numerics are deserialized as either Decimal or float depending on the way the
underlying Numeric is configured. There's a test for deserializing to Decimal, 
but I
haven't added the test for deserializing to float.

hopefully this is helpful.

Original comment by monkeylo...@gmail.com on 29 Dec 2008 at 4:08

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, monkey!  Great patch.  Applied in r620.

Original comment by jbel...@gmail.com on 29 Dec 2008 at 4:54