Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PostgreSQL array support broken for timestamps #13402

Closed
tkoenig opened this Issue · 10 comments

6 participants

@tkoenig

The activerecord changelog says that any datatype can be used to create an array column, but it seems to not work for timestamps:

Here is my migration:

create_table :sql_arrays do |t|
  t.timestamp :timestamps, array: true, default: []
  t.date :dates, array: true, default: []
  t.timestamps
end

And then creating a new entry in the console:

2.0.0p353 :006 > SqlArray.create(timestamps: [Time.now], dates: [Date.today])
D, [2013-12-19T12:39:57.855962 #6283] DEBUG -- :    (3.9ms)  BEGIN
D, [2013-12-19T12:39:57.859231 #6283] DEBUG -- :   SQL (2.6ms)  INSERT INTO "sql_arrays" ("created_at", "dates", "timestamps", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"  [["created_at", Thu, 19 Dec 2013 11:39:57 UTC +00:00], ["dates", [Thu, 19 Dec 2013]], ["timestamps", nil], ["updated_at", Thu, 19 Dec 2013 11:39:57 UTC +00:00]]
D, [2013-12-19T12:39:57.875126 #6283] DEBUG -- :    (15.7ms)  COMMIT
+----+------------+------------+-------------------------+-------------------------+
| id | timestamps | dates      | created_at              | updated_at              |
+----+------------+------------+-------------------------+-------------------------+
| 3  |            | 2013-12-19 | 2013-12-19 11:39:57 UTC | 2013-12-19 11:39:57 UTC |
+----+------------+------------+-------------------------+-------------------------+
1 row in set

As you see the timestamps array value gets submitted as nil. I'm using the latest stable version of rails (4.0.2)

@senny
Owner

@tkoenig can you write an executable test-case using this script as a foundation?

@prathamesh-sonpatki

Here is a test case https://gist.github.com/prathamesh-sonpatki/8059372
But the test is passing for me

@kuldeepaggarwal

Test case passing for me too.

@tkoenig

Hmm, thats interesting: test case is passing for me as well, but it fails for me in the console? Could anyone of you try that?

Loading development environment (Rails 4.0.2)
2.0.0-p0 :002 > Post.create(timestamps: [Time.now], dates: [Date.today])
(1.0ms)  BEGIN
SQL (44.3ms)  INSERT INTO "posts" ("dates", "timestamps") VALUES ($1, $2) RETURNING "id"  [["dates", [Tue, 07 Jan 2014]], ["timestamps", nil]]
(2.5ms)  COMMIT
 => #<Post id: 1, timestamps: nil, dates: [Tue, 07 Jan 2014]> 
@kuldeepaggarwal

@tkoenig Thanks for mentioning this, I just figured out the cause, will update soon.

@kuldeepaggarwal

Here is the gist for the failing test case.

@kuldeepaggarwal kuldeepaggarwal referenced this issue from a commit in kuldeepaggarwal/rails
@kuldeepaggarwal kuldeepaggarwal `datetime` and `timestamp` array attributes are saving correctly.
In PG adapter, when Model.time_zone_aware_attributes = true then:
  - Earlier, attributes of type `datetime` and `timestamp` are setting to
    nil if it is Array.
  - After this change, it will properly assign array of `timestamps`.
  - Fixes #13402
013360f
@kuldeepaggarwal kuldeepaggarwal referenced this issue from a commit in kuldeepaggarwal/rails
@kuldeepaggarwal kuldeepaggarwal `datetime` and `timestamp` array attributes are saving correctly.
In PG adapter, when Model.time_zone_aware_attributes = true then:
  - Earlier, attributes of type `datetime` and `timestamp` are setting to
    nil if it is Array.
  - After this change, it will properly assign array of `timestamps`.
  - Fixes #13402
22823a0
@senny
Owner

@tkoenig we'll address this issue after 4.1 was released. I assigned the 4.2 milestone.

@tkoenig

@senny :+1: thanks

@mhchen

Just FYI I tried to do something similar with datetimes today and seem to be running into the same issue.

@tkoenig tkoenig added the stale label
@senny senny removed the stale label
@kuldeepaggarwal kuldeepaggarwal referenced this issue from a commit in kuldeepaggarwal/rails
@kuldeepaggarwal kuldeepaggarwal `datetime` and `timestamp` array attributes are saving correctly.
In PG adapter, when Model.time_zone_aware_attributes = true then:
- Earlier, attributes of type `datetime` and `timestamp` are setting to
  nil if it is Array.
- After this change, it will properly assign array of `timestamps`.
- Fixes [#13402]
f170cf4
@kuldeepaggarwal kuldeepaggarwal referenced this issue from a commit in kuldeepaggarwal/rails
@kuldeepaggarwal kuldeepaggarwal `datetime` and `timestamp` array attributes are saving correctly.
In PG adapter, when Model.time_zone_aware_attributes = true then:
- Earlier, attributes of type `datetime` and `timestamp` are setting to
  nil if it is Array.
- After this change, it will properly assign array of `timestamps`.
- Fixes [#13402]
02178b1
@senny senny closed this in #15556
@vasilakisfil

Is that fixed ? I am running Rails 4.1.6 and I have the same issue.

edit: ah I see it's for rails 4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.