This project is archived and is in readonly mode.
ActiveRecord no longer populates uuid ids that were generated in the database
Reported by Jeff Dean | July 27th, 2010 @ 02:46 AM
I have an app with a postgres database. My primary keys are uuids that are populated by a postgres function. In Rails 2.3.8 when I create a record, the id field gets populated. In Rails RC the create succeeds, the id is not populated and the object is left in a very strange state.
Comments and changes to this ticket
-
Neeraj Singh July 27th, 2010 @ 04:05 AM
- Importance changed from to Low
Can you post your migration, model and the operation of creating the object.
-
Jeff Dean July 27th, 2010 @ 05:18 AM
Migration
class CreatePosts < ActiveRecord::Migration def self.up execute <<-SQL CREATE FUNCTION uuid_generate_v1() RETURNS uuid LANGUAGE c STRICT AS '$libdir/uuid-ossp', 'uuid_generate_v1'; CREATE TABLE posts ( id character varying(36) DEFAULT uuid_generate_v1() NOT NULL, title character varying ); SQL end def self.down drop_table :posts end end
Model
class Post < ActiveRecord::Base end
Test
require 'test_helper' class PostTest < ActiveSupport::TestCase test "save should be true" do # passes post = Post.new :title => "Foo" assert post.save, "Post save should be true" end test "save! should be true" do # passes post = Post.new :title => "Foo" assert post.save!, "Post save should be true" end test "save! should change the number of records" do # passes assert_difference('Post.count', 1) do Post.create! :title => "Foo" end end test "save assigns the id" do # fails! post = Post.create! :title => "Foo" assert post.id.present?, "Post should have an id" end end
Gemfile
source 'http://rubygems.org' gem 'rails', '3.0.0.rc' gem 'pg'
I've also attached a zip file of the app that might be easier to use to reproduce. I haven't taken the time to see whether this is broken in other adapters.
I've confirmed that on a brand-new rails 2.3.8 app with an identical migration all tests pass. I've also included a zip file with that example.
-
Jeff Dean July 27th, 2010 @ 05:18 AM
- no changes were found...
-
Santiago Pastorino February 2nd, 2011 @ 04:35 PM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 04:35 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>