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

Unable to create a record which has CURRENT_TIMESTAMP() as a default value in its schema #247

Closed
nownabe opened this issue May 10, 2023 · 0 comments · Fixed by #252
Closed
Assignees
Labels
api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@nownabe
Copy link
Contributor

nownabe commented May 10, 2023

Environment details

Ruby 3.2.2

  gem "activerecord", "7.0.4.3"
  gem "activerecord-spanner-adapter", "1.4.1"

Steps to reproduce

Run this script. Core part of it:

ActiveRecord::Schema.define do
  create_table :items do |t|
    t.string :name
    t.datetime :timestamp, null: false, default: -> { "CURRENT_TIMESTAMP()" }
  end
end

class Item < ActiveRecord::Base; end

class DefaultValueTest < Minitest::Test
  def test_current_timestamp
    item = Item.new(name: "foo")
    item.save!
  end
end

Error log

Dropped database 'default-value'
Created database 'default-value'
-- create_table(:items)
   -> 0.0056s
D, [2023-05-10T09:48:43.942591 #706767] DEBUG -- :   ActiveRecord::InternalMetadata Load (1.7ms)  SELECT `ar_internal_metadata`.* FROM `ar_internal_metadata` WHERE `ar_internal_metadata`.`key` = @p1 LIMIT @p2
D, [2023-05-10T09:48:43.949117 #706767] DEBUG -- :   SQL (0.0ms)  BEGIN
D, [2023-05-10T09:48:43.950904 #706767] DEBUG -- :   ActiveRecord::InternalMetadata Create (1.2ms)  INSERT INTO `ar_internal_metadata` (`key`, `value`, `created_at`, `updated_at`) VALUES (@p1, @p2, @p3, @p4)
D, [2023-05-10T09:48:43.952028 #706767] DEBUG -- :   SQL (0.9ms)  COMMIT
Run options: --seed 57676

# Running:

D, [2023-05-10T09:48:43.965357 #706767] DEBUG -- :   SQL (0.0ms)  BEGIN
D, [2023-05-10T09:48:43.966811 #706767] DEBUG -- :   Item Create (1.1ms)  INSERT INTO `items` (`name`, `id`) VALUES (@p1, @p2)
D, [2023-05-10T09:48:43.967901 #706767] DEBUG -- :   SQL (0.8ms)  ROLLBACK
E

Finished in 0.013998s, 71.4411 runs/s, 0.0000 assertions/s.

  1) Error:
DefaultValueTest#test_current_timestamp:
ArgumentError: no time information in "CURRENT_TIMESTAMP()"
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/time.rb:196:in `make_time'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/time.rb:383:in `parse'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-spanner-adapter-1.4.1/lib/active_record/type/spanner/time.rb:36:in `cast_value'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/type/value.rb:46:in `cast'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/type/helpers/accepts_multiparameter_time.rb:16:in `cast'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/type/value.rb:32:in `deserialize'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute.rb:168:in `type_cast'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute.rb:43:in `value'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute_set.rb:46:in `fetch_value'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/transactions.rb:403:in `block in restore_transaction_record_state'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute_set.rb:93:in `transform_values'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute_set.rb:93:in `map'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/transactions.rb:402:in `restore_transaction_record_state'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/transactions.rb:334:in `rolledback!'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:134:in `rollback_records'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:312:in `block in rollback_transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:309:in `rollback_transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:325:in `rescue in block in within_new_transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:322:in `block in within_new_transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-spanner-adapter-1.4.1/lib/active_record/connection_adapters/spanner/database_statements.rb:132:in `transaction'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/transactions.rb:302:in `save!'
    /home/shogow/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/suppressor.rb:54:in `save!'
    main.rb:123:in `test_current_timestamp'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
@nownabe nownabe added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 10, 2023
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. label May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants