not null error from PG on build_other call

I have this code in a stand alone script that uses nokogiri with activerecord to parse an xml file and initialise a database.

      begin       this_client = correspondent_f.build_client       rescue => e         puts("Rescued error in build.")         puts(e.backtrace)         puts(" ")         puts(correspondent_f.inspect.to_yaml)         raise e       end

Which, for a certain input record generates this error:

Rescued error in build. /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/abstract_adapter.rb:219:in `log' /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/postgresql_adapter.rb:550:in `execute' /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/abstract/database_statements.rb:265:in `update_sql' /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/postgresql_adapter.rb:561:in `update_sql' /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/abstract/database_statements.rb:49:in `update_without_query_dirty' /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ connection_adapters/abstract/query_cache.rb:18:in `update' . . . --- "#<Correspondent id: 1, correspondent_common_name: \"tnt skypak international exp.\", correspondent_legal_name: \"TNT SKYPAK INTERNATIONAL EXP.\", correspondent_legal_form: \"UNKN\", correspondent_legal_name_key: \"tntskypakinternationalexp\", correspondent_status: \"HOLD\", changed_at: \"2010-03-18 19:49:49\", changed_by: \"hp3000_client_import\", created_at: \"2010-03-18 19:49:49\", created_by: \"hp3000_client_import\", lock_version: 0>" /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record

/connection_adapters/abstract_adapter.rb:219:in `log': PGError: ERROR: null value in column "correspondent_id" violates not-null constraint (ActiveRecord::StatementInvalid) : UPDATE "clients"               SET "changed_at" = '2010-03-18 20:07:44', "correspondent_id" = NULL, "lock_version" = 1               WHERE id = 1               AND "lock_version" = 0         from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/ active_record/connection_adapters/postgresql_adapter.rb:550:in `execute'         from /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.5/lib/ active_record/connection_adapters/abstract/database_statements.rb: 265:in `update_sql' . . .

Now, I know that the record triggering the exception is a duplicate of one already previously loaded into the clients table. This in fact should trigger a validation error in the Correspondent class. But I do not see that validation error anywhere and I cannot understand why the correspondent_id value is null in the second case.

The Client class has this:

  belongs_to :correspondent   validates_associated   validates_presence_of :effective_from   validate :date_range

The Correspondent class has this:

  has_one :client

I am sure that this situation has a simple explanation and I hope that someone can provide it to me.