Skip to content

Commit d04c69b

Browse files
bartonipfilak-sap
authored andcommitted
Fixed filter not working for services that require URLEncoded filters
Closes #110 Signed-off-by: Jakub Filak <[email protected]>
1 parent 11297cc commit d04c69b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
- URL encode $filter contents - Barton Ip
11+
912
## [1.5.0]
1013

1114
### Added

pyodata/v2/service.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
from http.client import HTTPResponse
1515
from io import BytesIO
1616

17+
try:
18+
# For Python 3.0 and later
19+
from urllib.parse import quote
20+
except ImportError:
21+
# Fallback to urllib2
22+
from urllib2 import quote
23+
1724
from pyodata.exceptions import HttpError, PyODataException, ExpressionError
1825
from . import model
1926

@@ -592,7 +599,7 @@ def expand(self, expand):
592599
def filter(self, filter_val):
593600
"""Sets the filter expression."""
594601
# returns QueryRequest
595-
self._filter = filter_val
602+
self._filter = quote(filter_val)
596603
return self
597604

598605
# def nav(self, key_value, nav_property):

tests/test_service_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ def test_navigation_count_with_filter(service):
14501450

14511451
responses.add(
14521452
responses.GET,
1453-
"{0}/Employees(23)/Addresses/$count?$filter=City eq 'London'".format(service.url),
1453+
"{0}/Employees(23)/Addresses/$count?%24filter=City%2520eq%2520%2527London%2527".format(service.url),
14541454
json=3,
14551455
status=200)
14561456

0 commit comments

Comments
 (0)