Today I spent an inordinate amount of time fixing another DataMapper type error in my Postgres database. I had two models, Feedback and Blogposts, that wouldn’t save in production—only this time I had no error messages to guide me to that conclusion. When I submitted form data the app would just redirect to the next page without a peep in either the logs or the console, but nothing I entered persisted. The real kicker was that when I ran the app in development everything seemed to work just fine, but remotely it was like any data I entered just vanished into the “depths of the internet”.

In an effort to try and figure out what went wrong I littered my code with debug statements and chatted with people around the office… but it was to no avail. Then this afternoon, just as I was about to move on to do something else so that I didn’t feel entirely unproductive, Brian came in and sat down with me for 10 minutes. The code all looked good to him so we opened up the production app and tried a few things. Sure enough, Brian was creating objects and they were saving in every week but the current week. So then we took a look at the Weeks class that I’d built but nothing stood out. Then we tried to create something in the current week and lo and behold, it worked!

… and then it hit me. All of the sample data Brian was plugging in that worked and all of the sample data that I’d tried in development had a common trait: it was short. There were many places in my models where I was declaring my property type as String when it needed to be Text. While messing around in the app we were putting things in the input fields like “Test note”, “www.test.com” or even “kjasdkjf”. And in all of my unit tests I’d done the same thing, the test models were set up with parameters like {:title => “some title”, :note => “some note”, …}

But then when it came time to use the app in production I figured that I should always use real data, even when debugging. My blog title was an actual title and my url was the usual long URL, such as http://mikeebert.tumblr.com/post/29266941475/a-deploy-state-of-mind. DataMapper is very strict about its property types and if you declare a string you better keep it under 50 characters. Since my dummy data didn’t go over that I never noticed the problem.

The lesson? Use as close to actual data as possible during testing so that you’re more thoroughly prepared for production.

The other lesson? Despite DataMapper offering an auto_update! command that is supposed to take care of changes to your tables, it doesn’t actually always auto update—and doesn’t tell you when it fails to either. Even after I changed my property types to Text my models still weren’t saving. Thanks to the tip Mike showed me last Friday I figured out that I had to fire up a connection to my remote Postgres database and change the column types with a command such as: ALTER TABLE blogposts ALTER COLUMN url TYPE text;