Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.create! returns model with nil ID #690

Closed
hathawad opened this issue Nov 18, 2015 · 6 comments
Closed

Model.create! returns model with nil ID #690

hathawad opened this issue Nov 18, 2015 · 6 comments
Labels

Comments

@hathawad
Copy link

I have a production Rails 3.2.22 JRuby app that uses activerecord-jdbcpostgresql-adapter version '1.2.9'.
Recently though, I've tried to upgrade to 1.3.19 for some bug fixes (namely .pluck support). However, it seems that a trivial Rails 3.2.22 app is broken with any version of activerecord-jdbcpostgresql-adapter 1.3.0+.

Any Model.create calls return a model/object with a nil ID rather than the new ID (aka primary key).
I've created a bare bones rails app to demonstrate this:
https://github.com/jrl08d/jruby_test

To reproduce:

  • Check out app, bundle, create db's, etc
  • rails c (development or production)
  • Payment.create

The model that gets returned has a nil ID (which makes it more or less useless).

Loading production environment (Rails 3.2.22)
irb(main):001:0> Payment.create!
  ←[1m←[36mSQL (16.0ms)←[0m  ←[1mINSERT INTO "payments" ("amount", "created_at","notes", "updated_at") VALUES (NULL, '2015-11-18 22:21:59.000000', NULL, '2015-
11-18 22:21:59.000000')←[0m
=> #<Payment id: nil, amount: nil, notes: nil, created_at: "2015-11-18 22:21:59", updated_at: "2015-11-18 22:21:59">

Environment:

jruby 1.7.22 (1.9.3p551) 2015-08-20 c28f492 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_65-b17 +jit [Windows Server 2008 R2-amd64]

@hathawad
Copy link
Author

hathawad commented Dec 1, 2015

Should I chalk this up to no Rails 3.2 support?

@hathawad
Copy link
Author

This is not an issue on Rails 4.0
I suppose the world has moved on from Rails 3.2

@kares
Copy link
Member

kares commented Feb 26, 2016

3.2 should be still working - just did no have the time to look into it yet

@kares kares reopened this Feb 26, 2016
@hathawad
Copy link
Author

Fair enough, I'll test any PR if you need.

@kares
Copy link
Member

kares commented Feb 26, 2016

actually a small isolated test-case or piece of .rb script with everything in 1 place would help fix this sooner.

@kares
Copy link
Member

kares commented Mar 4, 2016

tried a script as well as your repo - all seems well, you should upgrade your JRuby 1.7.x version :

Loading production environment (Rails 3.2.20)
jruby-1.7.24 :001 > Payment.create!
  SQL (2.0ms)  INSERT INTO "payments" ("amount", "created_at", "notes", "updated_at") VALUES (NULL, '2016-03-04 12:10:13.820000', NULL, '2016-03-04 12:10:13.820000') RETURNING "id"
 => #<Payment id: 1, amount: nil, notes: nil, created_at: "2016-03-04 12:10:13", updated_at: "2016-03-04 12:10:13"> 

@kares kares closed this as completed Mar 4, 2016
@kares kares added the invalid label Mar 4, 2016
kares added a commit to kares/activerecord-jdbc-adapter that referenced this issue Mar 4, 2016
kares added a commit to kares/activerecord-jdbc-adapter that referenced this issue Mar 4, 2016
kares added a commit that referenced this issue Mar 9, 2016
* 1-3-stable: (25 commits)
  prepare for 1.3.20
  Retrieve AM::Type::Boolean::FALSE_VALUES for Rails 5.
  backwards compat for previous commit (tracking removed TRUE_VALUES in AR)
  [travis-ci] the system call regression also relates to a Rails change in 4.2
  [travis-ci] allow failures - yanother 9K BC timestamp issue + `` regression on 1.7.19
  [travis-ci] a bit more 9K test targets (with AR 4.1 besides 4.2) + fix oraclejdk8
  [test] trying to reproduce an issue with insert not returning id - without luck (#690)
  only mock mysql / mysql2 error under adapter /mysql/ and make sure db:create works
  use system instead of `` to run dumps (on < 4.0) as it has issues under 1.7.x
  [travis-ci] use latest JRuby 1.7 and do some testing against 9K, default JDK to 7
  [test] maintain 1.8 syntax compatibility
  [test] adjust derby tests to conform to how default values are expected on AR 4.2
  avoid column.default type_cast-ing on AR 4.2 - been causing some nesty bugs ... e.g. on postres as an array 'default' instance has been leaking into models
  [test] rename test file
  [test] adjust array column.default expectations to match AR under MRI on 4.1/4.2
  [test] specify a column default test-case - values should not be type-casted on 4.2
  [rake] test --use-color=t by default
  [test] match all *_test.rb files including those in sub-directories
  appraise latest 4.x versions
  [postgres] data_sources support - backport on AR 4.2 + hide internal constants compilant with rails/rails@d6eac0039abf2745f0fdf
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants