Skip to content

service: emit ge/le for the __range filter lookup - #325

Merged
phanak-sap merged 3 commits into
SAP:masterfrom
VitorCoelho:fix/filter-range-operators
Oct 26, 2026
Merged

phanak-sap merged 3 commits into
SAP:masterfrom
VitorCoelho:fix/filter-range-operators

Conversation

@VitorCoelho

Copy link
Copy Markdown
Contributor

Replaces #322, which GitHub closed when my fork was deleted by mistake. Same change, including the __le / __ge lookups discussed there.

What

GetEntitySetFilterChainable translated the __range lookup into the operators gte / lte:

service.entity_sets.Employees.get_entities().filter(ID__range=(20, 50))
# before: $filter=ID gte 20 and ID lte 50
# after:  $filter=ID ge 20 and ID le 50

The OData operator names __le / __ge are also accepted as lookups, next to the Django-style __lte / __gte (#113), with a comment on why both names exist.

Why

OData has no gte / lte operators. The comparison operators are eq, ne, gt, ge, lt, le (OData v2 URI conventions, 4.5 Filter System Query Option), so a service rejects the generated $filter with a syntax error. The __gte / __lte lookups already emit ge / le; __range now does the same.

How it was tested

  • The three existing tests that cover __range asserted the invalid URL. I updated them to the correct one: they fail on master and pass with the fix.
  • New tests for __le / __ge: they fail without the change.
  • pytest: 300 passed on Python 3.10 and 3.13.
  • CHANGELOG updated (Unreleased / Added and Fixed).

The __range lookup emitted the operators gte / lte, which are not OData
operators, so services rejected the $filter. It now emits ge / le, like
the __gte / __lte lookups already do.

The OData operator names __le / __ge are also accepted as lookups, next
to the Django-style __lte / __gte (SAP#113).

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Signed-off-by: VitorCoelho <vitorc195@gmail.com>

@phanak-sap phanak-sap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked this is the same code as in original #321 and fixes the problem and comments there.

@phanak-sap
phanak-sap merged commit 198ca80 into SAP:master Oct 26, 2026
42 checks passed
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

Successfully merging this pull request may close these issues.

2 participants