railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.87k stars 2.25k forks source link

When the column has `:uuid` type it's not possible to filter list by `is present`/`is_blank` filters #3669

Closed tomajask closed 5 months ago

tomajask commented 5 months ago

Describe the bug When filtering the records in the list view for table where column has an :uuid type of column and using is present/is blank filters it raises an exception:

ActionView::Template::Error
PG::InvalidTextRepresentation: ERROR:  invalid input syntax for type uuid: "" (ActionView::Template::Error)
LINE 1: ...ND table.column_id != '')) ORDER...

Reproduction steps

  1. Add a column to existing table with uuid type but without null: false constraint
  2. Go to admin panel, list view, search by this column using is present/is blank filter.
  3. It will result in 500 error.

Expected behavior When building a query, instead of:

WHERE ((table.column_id IS NOT NULL AND table.column_id != ''))

use just:

WHERE (table.column_id IS NOT NULL)

Additional context

It can be easily fixed by adjusting the following file: lib/rails_admin/adapters/active_record.rb

def unary_operators
  case @type
  when :boolean
    boolean_unary_operators
  when :integer, :decimal, :float
    numeric_unary_operators
  when :uuid
    uuid_unary_operators
  else
    generic_unary_operators
  end
end

(...)
alias_method :uuid_unary_operators, :boolean_unary_operators
tomajask commented 5 months ago

Ok, now I noticed that the fix is there on master but it was not released yet 🤷🏼 https://github.com/railsadminteam/rails_admin/commit/647347c48de65b49f8f63a767289484599f7b638 https://github.com/railsadminteam/rails_admin/pull/3629