Eric,
Instance_eval in AR may have threading implications. [Rails is suppose
to be "mostly" thread-safe now, whatever that means.] Aside from that,
you should submit a bug report with tests that demonstrate the behavior,
and offer a patch, and see what they say.
It definitely makes sense to trigger a validation rather than a
StatementInvalid error in the app layer, but I'm not sure about in the
framework layer. I think if the query is being sent and the DB rejects
it, then there is an incongruity between the DB and the ORM that
shouldn't exist. Is this a bug in the DB, the ORM, or the application?
I don't think it's a bug in either the DB or the ORM software. I think
the developer set up the application incorrectly. The ORM is suppose to
be DB agnostic. Postgres, for example, doesn't block off memory for
varchars any differently than it does for a string or text, so it
doesn't care how long the string is. There is only one reason to add a
constraint here -- specifically, for the purpose of forcing a
constraint. By convention, this ORM says don't do that. Put all
constraints in the model of the application, not in the DB. If you have
an arbitrary constraint like field length, put it as a validation in the
model for that field.
So in a Rails app, the DB should not have length or null constraints,
unless you have a scenario where you specifically want a
StatementInvalid error generated. Otherwise, that's what the
validations are for, and they belong visibly in the model, not buried in
the ORM.
2¢
-CLR