Skip to content
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

Closed
wants to merge 8 commits into from
Closed

A few improvements #111

wants to merge 8 commits into from

Conversation

bartonip
Copy link
Contributor

@bartonip bartonip commented Jun 26, 2020

  • Added <, <=, >, >= operators for GetEntitySetFilter
  • Made headers attribute on ODataHttpRequest actually affect the headers
  • Allow PATCH or PUT to be specified for EntityModifyRequest

@bartonip bartonip changed the title Added additional operators to GetEntitySetFilter A few improvements Jun 26, 2020
### Fixed
- URL encode $filter contents - Barton Ip
- Headers attribute on ODataHttpRequest - Barton Ip
Copy link
Contributor

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.

@filak-sap
Copy link
Contributor

Well done! Thank you. I pushed these commits:

90016c2
a735037
5a1040a

@filak-sap filak-sap closed this Jun 26, 2020
self._connection = connection
self._url = url
self._handler = handler
self._headers = headers
self.headers = headers
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

Copy link
Contributor

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.

@@ -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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@@ -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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@@ -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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@@ -639,6 +644,7 @@ def get_headers(self):

return {
'Accept': 'application/json',
**self.headers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@@ -699,6 +705,7 @@ def get_method(self):
def get_headers(self):
return {
'Accept': 'application/json',
**self.headers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@@ -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}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one

@filak-sap
Copy link
Contributor

@bartonip OMG, my apologies, I skipped that commit - I saw "M" at the commit summary, I my brain interpreted it as a merge commit.

@filak-sap filak-sap reopened this Jun 27, 2020
Copy link
Contributor

@filak-sap filak-sap left a 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).

@@ -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={}):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

self._connection = connection
self._url = url
self._handler = handler
self._headers = headers
self.headers = headers
Copy link
Contributor

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.

@@ -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
Copy link
Contributor

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()
Copy link
Contributor

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.

@filak-sap
Copy link
Contributor

I pushed a slightly modified and squashed version:
2d7cd16

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.

@filak-sap filak-sap closed this Jun 28, 2020
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