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

Error Starting Rails Admin: Unsupported field datatype: timestamptz in rails admin 3.1.2 #3615

Open
carlosgab83 opened this issue Mar 28, 2023 · 2 comments

Comments

@carlosgab83
Copy link

carlosgab83 commented Mar 28, 2023

Having a postgreSQL table with a timstamp with time zone field type produce:

Unsupported field datatype: timestamptz

error while rails_admin access the model, http://localhost:3000/client

Reproduction steps

  • Have a table with created_at or updated_at fields with type timstamp with time zone
  • Have the correspondent model
  • Access the url http://localhost:3000/client
  • Get the error

Expected behavior
It must accept this data type as previous versions does

Stack

  • Rails 7.0.4.3
  • Ruby 3.1.3
  • gem rails_admin 3.1.2
  • gem pg 1.4.6
  • Postgres server 12.9

Stack trace

rails_admin (3.1.2) lib/rails_admin/config/fields/types.rb:14:in `block in load'
rails_admin (3.1.2) lib/rails_admin/config/fields/types.rb:14:in `fetch'
rails_admin (3.1.2) lib/rails_admin/config/fields/types.rb:14:in `load'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:17:in `block in <module:Fields>'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:57:in `block (2 levels) in factory'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:57:in `each'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:57:in `detect'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:57:in `block in factory'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:52:in `each'
rails_admin (3.1.2) lib/rails_admin/config/fields.rb:52:in `factory'
rails_admin (3.1.2) lib/rails_admin/config/has_fields.rb:135:in `_fields'
rails_admin (3.1.2) lib/rails_admin/config/has_fields.rb:138:in `_fields'
rails_admin (3.1.2) lib/rails_admin/config/has_fields.rb:109:in `all_fields'
rails_admin (3.1.2) lib/rails_admin/config/has_fields.rb:84:in `fields'
rails_admin (3.1.2) app/controllers/rails_admin/main_controller.rb:127:in `get_collection'

Context

If i change the type of the field to "timestamp without time zone", it works fine, but i need the time zone.

I know this was supported because it worked with rails_admin 2 and rails 5.

Inspecting the error in the gem i can see there are not a :timestamptz key in the types registry, but :timestamp only.

rails_admin (3.1.2) lib/rails_admin/config/fields/types.rb:14

>> @@registry.keys
=> [:text, :action_text, :string, :enum, :active_record_enum, :file_upload, :active_storage, :belongs_to_association, :boolean, :bson_object_id, :composite_keys_belongs_to_association, :datetime, :date, :numeric, :decimal, :dragonfly, :paperclip, :carrierwave, :multiple_file_upload, :multiple_active_storage, :multiple_carrierwave, :float, :has_many_association, :has_and_belongs_to_many_association, :has_one_association, :integer, :password, :polymorphic_association, :hidden, :serialized, :shrine, :time, :timestamp, :color, :simple_mde, :ck_editor, :code_mirror, :wysihtml5, :froala, :json, :jsonb, :inet, :uuid, :citext]

PostgresSQL table definition:

CREATE TABLE public.clients (
    id integer NOT NULL,
    name character varying(100) NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone,
    slug character varying(100) NOT NULL
);

Model definition:

app/models/client.rb

class Client < ApplicationRecord
end
@carlosgab83 carlosgab83 changed the title Unsupported field datatype: timestamptz in rails admin 3.1.2 Error Starting Rails Admin: Unsupported field datatype: timestamptz in rails admin 3.1.2 Apr 12, 2023
@shamangeorge
Copy link

shamangeorge commented Apr 17, 2023

You could monkey patch it. In order to overcome this error for our project we added a timestamptz.rb file in the folder lib/rails_admin/config/fields/types/ and we then had to require it explicitly in lib/rails_admin/config/fields/types/all.rb

The contents of timestamptz.rb can be the same as timestamp.rb

@carlosgab83
Copy link
Author

carlosgab83 commented Apr 18, 2023

Hi @shamangeorge, Thanks for your response. It works!.

Some considerations for someone facing the same issue:

  • In my case it was not necessary to explicity require the new file timestamptz.rb in lib/rails_admin/config/fields/types/
  • It obvious but you need to change the class name of the new file to Timestamptz

It works as expected, even is applying the time zone correctly when save/update a record.

However i think this issue must be fixed in order to avoid this workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants