Skip to content

0.27.0

Choose a tag to compare

@woylie woylie released this 10 Aug 12:41
· 31 commits to main since this release
Immutable release. Only release title and notes can be modified.
d49685a

Changed

  • Require the ecto_type option for join fields and custom fields.
  • Raise a Flop.UnknownFieldError instead of a FunctionClauseError when
    Flop.Schema.field_info/2, Flop.Schema.get_field/2 or
    Flop.Filter.allowed_operators/2 is called with a field that is not
    configured in the schema.
  • Reject compound and alias fields as order fields for cursor pagination during
    validation. They can still be used with offset and page based pagination.
  • Raise an ArgumentError instead of ignoring the filter when an unsupported
    operator is applied to a compound field. This only affects unvalidated
    filters.

Fixed

  • Return an empty list from Flop.aliases/2 if the order_by parameter is
    nil, instead of raising a Protocol.UndefinedError.
  • Build the meta struct in Flop.meta/3 if neither a page size nor a limit is
    set, instead of raising an ArithmeticError.
  • Fall back to the first page or to offset 0 in Flop.set_page/2 and
    Flop.set_offset/2 if the given string is not a number, instead of raising
    an ArgumentError.
  • Merge adapter options passed at the call site with the options set on the
    backend module, instead of discarding them.

Security

  • Limit the number of filters that can be applied in one request to 20 by
    default. Configurable with the max_filters option.
  • Remove the debug log on validation errors. It logged the changeset, which
    contains the user-supplied filter values. The errors are returned to the
    caller in the Flop.Meta struct, so nothing is lost.

How to upgrade

Add the ecto_type options to all Flop.Schema derivations that don't have it
already:

  @derive {
    Flop.Schema,
    filterable: [],
    sortable: [],
    adapter_opts: [
      join_fields: [
        owner_age: [
          binding: :owner,
          field: :age,
+         ecto_type: :integer
        ]
      ],
      custom_fields: [
        partial_id: [
          filter: {__MODULE__, :partial_id_filter, []},
+         ecto_type: :string
        ]
      ]
    ]
  }

Filter lists longer than 20 are now rejected with a validation error on
filters. If your query handles longer filter lists, pass the max_filters
option:

Flop.validate_and_run(Pet, params, for: Pet, max_filters: 50)

The option can also be set via application environment or backend module.