Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Delete me

#6405

Oh nevermind

Reported by ronin-68998 (at lighthouseapp) · February 9th, 2011 @ 11:19 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. ronin-68998 (at lighthouseapp)
    ronin-68998 (at lighthouseapp)

    Found the issue:

    This should at least raise a warning or be documented that you're doing something silly or non-conventional.

    Bug:

    Given the following migration you'll notice two columns with :null => false, in the following model 'Broken' you'll notice one validates_presence_of.

    If you run the following code:

    Broken.create({:first_name => 'Test', :last_name => 'User'})
    => PGError: ERROR:  null value in column "first_name" violates not-null constraint
    
    Works.create({:first_name => 'Test', :last_name => 'User'})
    => YAY
    

    :last_name is ignored before insert because it's not in the validator chain, that's clearly undocument or faulty behavor for postgresql, even though the value for :last_name was passed.

    class CreateUsers < ActiveRecord::Migration
      def self.up
        create_table :users do |t|
    
          # names!
          t.string :first_name,             :null => false
          t.string :last_name,              :null => false
    
          t.timestamps
        end
      end
    
      def self.down
        drop_table :users
      end
    end
    
    class Works < ActiveRecord::Base
      set_table_name 'users'
    
      validates_presence_of :first_name, :on => :create
      validates_presence_of :last_name, :on => :create
    
    end
    
    class Broken < ActiveRecord::Base
      set_table_name 'users'
    
      validates_presence_of :first_name, :on => :create
    
    end
    

    February 10th, 2011 @ 12:59 AM

  2. ronin-68998 (at lighthouseapp)
    ronin-68998 (at lighthouseapp)
    • Title changed from ActiveRecord create on Postgres induces not-null constrains to Delete me

    February 10th, 2011 @ 01:26 AM

  3. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid
    • Importance changed from to Low

    February 10th, 2011 @ 05:42 AM