production and development - differing behaviour

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.

1) caching, am using uncached in my method
2) timezones, env.rb is the same UTC in both
3) browser behaviour, maybe? still need to try this, unlikely though?
4) 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
5) dates on the server and my mac, I did ./script/console then Time.now
and both reported the same as expected
6) apache / passenger config on the server - could this be important?

What happens when you run in production mode on your mac (I take it
that your mac is the development box)?

Same thing - it works on my MacBook in prod mode with the production
data loaded. Not on my server though.

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.

Peter Hickman wrote in post #978144:

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.

Good idea - will try this and report back.

OK, tested...

on my server, in production,

./script/console

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]

so it works... returns a single app as I might expect

in the browser I do...

http://server_ip/apps.json?date_from=2011-01-28T13:58:38Z&date_to=2011-01-28T13:58:38Z

I get

[ ]

So nothing, it doesn't find the app.

in dev on my mac

I do a similar thing

script console

App.time_query("2011-01-28 07:07:14","2011-01-28 07:07:14")

=> [#<App id: 1167, name: "Ball Dash Pro", bla bla

one app returned as expected...

browser

http://localhost:3000/apps.json?date_from=2011-01-28T07:07:14Z&date_to=2011-01-28T07:07:14Z

Guess what ?

[{"app":{"name":"Ball Dash
Pro","popularity":2,"created_at":"2011-01-14T10:00:52Z","seller_name":"NextGen
Entertainment.... bla bla...

One app returned as expected !

what else can I look at ?

bingo bob wrote in post #978210:

OK, tested...

on my server, in production,

./script/console

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]

so it works... returns a single app as I might expect

in the browser I do...

http://server_ip/apps.json?date_from=2011-01-28T13:58:38Z&date_to=2011-01-28T13:58:38Z

I get

[ ]

So nothing, it doesn't find the app.

Testing this way is risky: you might have different data in the two DBs.
Instead, compare the SQL generated by the two queries.

Best,

OK, tested...

on my server, in production,

./script/console

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)

Fred

Ok, that makes sense, but how do I see the SQL generated in production.

It's logged by default in dev, but not in prod AFAIK.

Ok, that makes sense, but how do I see the SQL generated in production.

It's logged by default in dev, but not in prod AFAIK.

Then change the log level ( in environments/production.rb)

I thought that's how you had to format dates in a URL to have them
recognised by rails.

I'll try it the same as on the console then.

Logging now on in production for a while. so that helps.

When the URL is crafted this way it works...(I thought I'd cracked it)

IP/apps.json?date_from=2011-01-28%2013:58:38&date_to=2011-01-28%2013:58:38

log

  Parameters: {"date_to"=>"2011-01-28 13:58:38",
"date_from"=>"2011-01-28 13:58:38"}
  App Load (0.0ms) SELECT * FROM `apps` WHERE (updated_at >=
'2011-01-28 13:58:38' AND updated_at <= '2011-01-28 13:58:38' AND deal =
true) ORDER BY updated_at DESC, updated_at ASC LIMIT 20

But then I change the time to 11am "1100" it does this....!

IP/apps.json?date_from=2011-01-28%1100:58:38&date_to=2011-01-28%1100:58:38

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

Why? How? What next?

Or to put it another way, what's the best/correct way to specify
DATETIMEs in a URL.

Logging now on in production for a while. so that helps.

'2011-01-28 13:58:38' AND updated_at <= '2011-01-28 13:58:38' AND deal =
true) ORDER BY updated_at DESC, updated_at ASC LIMIT 20

But then I change the time to 11am "1100" it does this....!

IP/apps.json?date_from=2011-01-28%1100:58:38&date_to=2011-01-28%1100:58:38

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)

Fred.

Is this to do with the T and Z delimiters not being recognised by mysql?