Skip to content

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

@tomajask

Description

@tomajask

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

  • rails version: 7.0.5.1
  • rails_admin version: 3.1.2
  • rails_admin npm package version:
  • full stack trace (if there's an exception)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions