DataError is a psycopg2 exception.   psycopg2 in turn is doing what PG's client 
API provides for them.  So if you wanted those messages to name the column 
that's the target of an INSERT or UPDATE you'd have to look into improving 
psycopg2 and/or how Postgresql's client system works.

Normally, for debugging, you'd examine the SQL statement in the error as well 
as the bound parameters.    It's usually pretty obvious which field is wrong.


To catch the exception when the field name is known,  can be done in the ORM on 
a field by field basis with @validates, 
http://www.sqlalchemy.org/docs/orm/mapper_config.html#simple-validators , or 
more across the board using attribute-level event listeners.   But you'd have 
to design the data validation scheme manually, it's a lot of effort.

A TypeDecorator can also be used to validate data but that exception would also 
occur in a context where the "column" name is not present - as types can be 
used in any arbitrary expression.



On Nov 1, 2011, at 2:42 AM, Tate Kim wrote:

> hi, I'm using sqlalchemy 0.7.3 and postgresql 9 with psycopg2 and python 2.7.
> 
> 
> When I put wrong type of data(ex: 'some string' into Integer field), I get 
> DataError exception in commit phase.
> 
> This is so expected result, but i think it would be great to get more 
> specific data which can tell model's field name that causes an exception.
> 
> I looked up DataError's field such as 'orig', 'params', 'statement', but i 
> could not figure it out with this.
> 
> How can i achieve this ?
> 
> 
> Regards,
> 
> Tate
> 
> -- 
> 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.

-- 
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.

Reply via email to