Document String and Text propertly default length limits #37

Merged
merged 1 commit into from Mar 31, 2012

Projects

None yet

2 participants

@jonjensen
Contributor

Hi. I just spent too long trying to figure out why a new String property I added was failing validation. The data I was trying to insert was only 64 characters, which is far too short to trigger any kind of gut reaction that the length could be a problem. The documentation didn't give any indication there is a built-in hardcoded default limit. The validation failure message didn't indicate what was causing the failure.

Anyway, once I dug into the source I quickly found the default length limit culprit. I documented it here in hopes of saving someone else the same pain.

Personally I'd prefer to see no length limit by default; if I wanted a length validation I would've added one to the model or used the earlier example DataMapper::Property::String.length(255) etc. Any default is going to be arbitrary, and the Text limit seems just as likely to trip someone up who's not expecting any limit at all. That's my $0.02 on it, but at the very least I wanted to get the limits documented.

Thanks,
Jon

@dkubb dkubb merged commit 3608993 into datamapper:master Mar 31, 2012
Owner
dkubb commented Mar 31, 2012

Thanks for this.

It's true that this trips up a lot of peolpe. Most data store require some kind of limit when storing a string. Even the ones that have "infinite" string fields should have practical limits specified IMHO. What do you think about bumping the default maximum to 255? This would seem to be a fairly common limit for other data stores.

Contributor

I think any default is bad because none of the SQL datastores I work with have any default for VARCHAR. Postgres allows bare VARCHAR with no limit at all. MySQL and Oracle require a default but it's totally arbitrary, and can be VARCHAR(1000) or more.

I've seen people set limits of 300 or more, and an implicit default of 255 would introduce a new painful corner case where <= 255 works, which may be the most common case, but >= 255 and < 300 would fail.

TEXT has no length limit on Postgres or MySQL. Oracle doesn't have an equivalent datatype that I know of.

It just seems better to have no implicit default to me. If I've put a length limit on a varchar field and not told DataMapper about it, that's no more DataMapper's fault than if I have a CHECK constraint it knows nothing about.

Anyway, thanks for the quick reply!

Owner
dkubb commented Mar 31, 2012

That works for cases where the schema is already present, but may be problematic when using auto migration or auto upgrading.

I suppose another option would be to warn when you try to auto migrate/upgrade a table with a CHAR column without any specified limit and the underlying db uses it's own implict default limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment