I’ll elaborate with code and URLs if it helps but I’ll start just
describing the problem and seeing if anyone can help me out with some
ideas.
I have a method which returns some objects as json via a time_query
method on my model - the time query takes a couple of parameters
date_from and date_to. The method should return objects within that
range (date attribute I’m querying is updated_at). This is pretty much
for background, it works fine in development, it doesn’t behave as
expected in production.
A small test for me is to simply craft a URL which isolates a single
record on the basis of it’s updated_at time and returns it to me, ie
makes a really tiny time frame between the two dates and get the record
I’d expect back - works in dev (i can return a single record), does not
work in prod (I can’t).
I’m stuck. What else causes dev and prod to behave differently in such
circumstances?
Things I’ve tried / occured to me - still no luck.
caching, am using uncached in my method
timezones, env.rb is the same UTC in both
browser behaviour, maybe? still need to try this, unlikely though?
databases, it’s mysql on dev and prod, UTF8, I’ve just tried dumping
the production data to dev and it worked in dev with that production
data
dates on the server and my mac, I did ./script/console then Time.now
and both reported the same as expected
apache / passenger config on the server - could this be important?
Do you have the same database on the two machines (ie both running
MySQL or something).
As this is a method in a model have you checked it from the console in
production mode on the production server? If it doesn’t work when
directly calling the model method you can eliminate the browser as
being an issue.
Do you have the same database on the two machines (ie both running
MySQL or something).
Yes - same DB on both machines, mysql.
As this is a method in a model have you checked it from the console in
production mode on the production server? If it doesn’t work when
directly calling the model method you can eliminate the browser as
being an issue.
App.time_query(“2011-01-28 13:58:38”,“2011-01-28 13:58:38”)
=> [#<App id: 700, name: “Dream Home HD”, description: "LIMITE… bla
bla bla]
Why did you format the dates differently in the console versus in the
URL? Depending on who is parsing those strings it could be obscure
differences between versions if mysql, locale or date libraries (eg if
different hosts had different versions of libicu)
Processing AppsController#index to json (for 90.211.81.40 at 2011-01-29
07:06:18) [GET]
Parameters: {“date_to”=>“2011-01-28\02100:58:38”,
“date_from”=>“2011-01-28\02100:58:38”}
App Load (610.0ms) SELECT * FROM apps WHERE (updated_at >=
‘2011-01-2800:58:38’ AND updated_at <= ‘2011-01-2800:58:38’ AND deal =
true) ORDER BY updated_at DESC, updated_at ASC LIMIT 20
You haven’t ch age the time to 11am. You’ve added %11 to the URL which
will translate to some unprintable control character so mysql can no
longer parse the date. It seems like you’re last passing the date
strings you get straight through to mysql so I suggest you lookup on
mysql what date formats it is guaranteed to understand (or in your
controller, ensure that input is appropriately coerced)