I am developing a library to do Active Record style validations on SA
declarative instances:

http://bitbucket.org/rsyring/sqlalchemy-validation/src/tip/savalidation/

I know there are differences of opinion on the value of doing
validation like this, but I am really hoping to avoid that discussion
as I think it will be a valuable addition if I can get it implemented
correctly.

I am running into an issue with getting my hooks in the right place.
I would like to be able to do the following:

* I would like default values to have been applied to the instance if
applicable before validation, i.e. i want to see the instance as a
mirror of what the flushed SQL will look like
* I would like to be able to have multiple models fail validation i.e.
I want to get details on as many errors as possible before raising an
exception

I was initially using before_insert and before_update on the mapper
extension and trying to "catch" the errors on those instances in the
session extension.  However, before_flush() gets called before the
mapper extension's before_insert/update, so that didn't work.

So, Ideally, my work flow would look something like:

- before_insert/before_update called on each instance
-- instance.do_validation() called; any errors are stored on the
instance and the process continues
- I loop through the session looking for instances with validation
errors
-- if I find any, I throw a ValidationError exception
- SQL is actually flushed to the DB

I really am in over my head a bit in SA internals though, so feel free
to let me know if I am missing the big picture.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en.

Reply via email to