-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A few improvements #111
A few improvements #111
Conversation
bartonip
commented
Jun 26, 2020
•
edited
Loading
edited
- Added <, <=, >, >= operators for GetEntitySetFilter
- Made headers attribute on ODataHttpRequest actually affect the headers
- Allow PATCH or PUT to be specified for EntityModifyRequest
### Fixed | ||
- URL encode $filter contents - Barton Ip | ||
- Headers attribute on ODataHttpRequest - Barton Ip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry but I cannot see any code for this last changelog entry.
pyodata/v2/service.py
Outdated
self._connection = connection | ||
self._url = url | ||
self._handler = handler | ||
self._headers = headers | ||
self.headers = headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes happen in the following lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to make the member public? If so, I would prefer a property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, this way we can also have a set_headers method that can append/update headers.
pyodata/v2/service.py
Outdated
@@ -284,7 +284,7 @@ def execute(self): | |||
# pylint: disable=assignment-from-none | |||
body = self.get_body() | |||
|
|||
headers = {} if self._headers is None else self._headers | |||
headers = self.headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should have headers = dict(self.headers)
to make sure we don't polute someones dict.
pyodata/v2/service.py
Outdated
@@ -351,7 +351,7 @@ def get_path(self): | |||
return self._entity_set_proxy.last_segment + self._entity_key.to_key_string() | |||
|
|||
def get_headers(self): | |||
return {'Accept': 'application/json'} | |||
return {'Accept': 'application/json', **self.headers} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
pyodata/v2/service.py
Outdated
@@ -448,7 +448,7 @@ def get_body(self): | |||
return json.dumps(self._get_body()) | |||
|
|||
def get_headers(self): | |||
return {'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'X'} | |||
return {'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'X', **self.headers} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
pyodata/v2/service.py
Outdated
@@ -541,7 +546,7 @@ def get_body(self): | |||
return json.dumps(body) | |||
|
|||
def get_headers(self): | |||
return {'Accept': 'application/json', 'Content-Type': 'application/json'} | |||
return {'Accept': 'application/json', 'Content-Type': 'application/json', **self.headers} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
pyodata/v2/service.py
Outdated
@@ -639,6 +644,7 @@ def get_headers(self): | |||
|
|||
return { | |||
'Accept': 'application/json', | |||
**self.headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
pyodata/v2/service.py
Outdated
@@ -699,6 +705,7 @@ def get_method(self): | |||
def get_headers(self): | |||
return { | |||
'Accept': 'application/json', | |||
**self.headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
pyodata/v2/service.py
Outdated
@@ -1433,7 +1452,7 @@ def get_boundary(self): | |||
|
|||
def get_headers(self): | |||
# pylint: disable=no-self-use | |||
return {'Content-Type': 'multipart/mixed;boundary={}'.format(self.get_boundary())} | |||
return {'Content-Type': 'multipart/mixed;boundary={}'.format(self.get_boundary()), **self.headers} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one
@bartonip OMG, my apologies, I skipped that commit - I saw "M" at the commit summary, I my brain interpreted it as a merge commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, due to lack coffein or something else, I made the method get_headers public, but the goal was to create a method for ancestors of the class ODataHttpRequest to return static or customer headers and not the actual headers for HTTP request - my idea is that a child class should not be forced to full fill parents responsibility which is to use the headers given in the constructor or set via a property/member in HTTP request. (We might add add the prefix _ to the method name).
pyodata/v2/service.py
Outdated
@@ -235,11 +235,11 @@ def __repr__(self): | |||
class ODataHttpRequest: | |||
"""Deferred HTTP Request""" | |||
|
|||
def __init__(self, url, connection, handler, headers=None): | |||
def __init__(self, url, connection, handler, headers={}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, don't use objects for default values. The default value is instantiated only once. In this case, once someone populates headers, all other consecutive calls of ODataHttpRequests() will receive the hedaers directory populate.
Or was that your intention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my intention for my use case, a bit hacky but works well for us without needing to set global params.
However, in retrospect you are correct we should not be forcing the headers on all descendant classes as this is definitely not expected behaviour.
I will revise this to use the dict type as the default value.
pyodata/v2/service.py
Outdated
self._connection = connection | ||
self._url = url | ||
self._handler = handler | ||
self._headers = headers | ||
self.headers = headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to make the member public? If so, I would prefer a property.
pyodata/v2/service.py
Outdated
@@ -284,7 +284,7 @@ def execute(self): | |||
# pylint: disable=assignment-from-none | |||
body = self.get_body() | |||
|
|||
headers = {} if self._headers is None else self._headers | |||
headers = self.headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should have headers = dict(self.headers)
to make sure we don't polute someones dict.
@@ -284,7 +284,7 @@ def execute(self): | |||
# pylint: disable=assignment-from-none | |||
body = self.get_body() | |||
|
|||
headers = {} if self._headers is None else self._headers | |||
headers = self.headers | |||
|
|||
# pylint: disable=assignment-from-none | |||
extra_headers = self.get_headers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you keep the get_headers method as it is this patch, then we don't need the line 287 at all. But I would rather keep the line 287 and remove all occurences of slef.headers from the redefined get_headers. I don't think its a good idea to force descendant classes to use the headers class member to return the correct headers - this is up to the parent class.
I pushed a slightly modified and squashed version: I hope you don't mind I kept you as author even thought I changed the patch - I prefer clean history where every single commit make sense. |