Skip to content

Feature request: setting to ignore or throw for filters and sorts on prevented properties #112

Closed

Description

@pdevito3

Summary

Add a setting that selects what QueryKit does when a filter or a sort uses a property with PreventFilter() or PreventSort():

  • Ignore (default): QueryKit removes the filter clause or skips the sort clause. The rest of the filter or sort still runs.
  • Throw: QueryKit throws a QueryKitException subclass that names the property.

Current behavior

After the property resolver work, a prevented property is always ignored:

  • The parser removes a prevented filter clause. This is true for the member name and for the query name.
  • SortParser skips a prevented sort clause.

Before that work, the behavior was not the same for all forms. A property with both PreventFilter() and PreventSort() threw InvalidOperationException (wrapped in a ParsingException) when the filter used its query name. With the member name, the same clause was removed.

Why a setting

Some APIs want to silently ignore fields that a client cannot use. Other APIs want to return a 400 so that the client knows that its filter or sort had no effect. Ignore stays the default, so current users see no change.

Proposed shape

var config = new QueryKitConfiguration(config =>
{
    config.PreventedPropertyBehavior = PreventedPropertyBehavior.Throw; // default: Ignore
});

The name is only a proposal. The setting applies to filters and sorts.

When the setting is Throw:

  • A filter clause on a property with PreventFilter() throws. This includes the property on the right side, in arithmetic, and in a property list.
  • A sort clause on a property with PreventSort() throws.
  • A derived property or a custom operation with PreventFilter() or PreventSort() throws the same way.
  • The exception derives from QueryKitException, so a single catch handles it.

Out of scope

Allow-list mode (#108) is a separate feature.

Activity

  1. pdevito3 commented on Nov 1, 2026

    @pdevito3
    OwnerAuthor

    Examples from a downstream app (QueryKit 1.16.2)

    The "Current behavior" section above is out of date. 1.16.2 has IgnoredClauseBehavior, and its default ReplaceWithTrue turns a prevented clause into true. A client that filters on a prevented property gets every row, and gets no error.

    public class Item { public string? Title { get; set; } public string? Secret { get; set; } }
    
    var config = new QueryKitConfiguration(c => c.Property<Item>(x => x.Secret).PreventFilter());

    Rows: abc, "abc", abc", [a], and secret row (the only row with Secret = "x").

    Filter Setting Result
    Secret == "x" ReplaceWithTrue (default) 5 rows. The client asked for 1 row.
    Secret == "x" || Title == "abc" ReplaceWithTrue 5 rows
    Secret == "x" && Title == "abc" ReplaceWithTrue 1 row (abc)
    Secret == "x" || Title == "abc" Remove 1 row (abc). The secret row is missing, and the client does not know why.

    The app wants a 400 here. It cannot use PreventFilter for this, so it walks the parsed expression with an ExpressionVisitor and throws when the expression reads the member. It does this for two members: a concurrency version (Postgres has no order for xid, so a range or a sort fails with a 500), and a member that the handler fills after the query.

    Suggestion on the shape

    IgnoredClauseBehavior already exists, so a third value Throw can be the setting. Then no new PreventedPropertyBehavior setting is necessary. With AllowUnknownProperties = false, an unknown property already throws UnknownFilterPropertyException. A prevented property can throw a subclass of QueryKitException that has a PropertyName property (see #209).

  2. added a commit that references this issue on Nov 2, 2026
    f87ab79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions