Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

PostgreSQL array support broken for timestamps #13402

Closed
tkoenig opened this Issue Dec 19, 2013 · 10 comments

Comments

Projects
None yet
6 participants

tkoenig commented Dec 19, 2013

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)

Member

senny commented Dec 20, 2013

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

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

Contributor

kuldeepaggarwal commented Dec 20, 2013

Test case passing for me too.

tkoenig commented Jan 7, 2014

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]> 
Contributor

kuldeepaggarwal commented Jan 7, 2014

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

Contributor

kuldeepaggarwal commented Jan 7, 2014

Here is the gist for the failing test case.

kuldeepaggarwal added a commit to kuldeepaggarwal/rails that referenced this issue Jan 8, 2014

`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

kuldeepaggarwal added a commit to kuldeepaggarwal/rails that referenced this issue Jan 8, 2014

`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
Member

senny commented Jan 8, 2014

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

tkoenig commented Jan 8, 2014

@senny 👍 thanks

mhchen commented Jan 13, 2014

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 Apr 23, 2014

@senny senny removed the stale label Apr 24, 2014

kuldeepaggarwal added a commit to kuldeepaggarwal/rails that referenced this issue Jun 4, 2014

`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]

kuldeepaggarwal added a commit to kuldeepaggarwal/rails that referenced this issue Jun 4, 2014

`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]

@senny senny closed this in #15556 Jun 7, 2014

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