Repository navigation
service: Support null (#79) - #189
Conversation
|
I think it is worth doing if there is genuine need for this - but not like additional hardcoded parameter for client and service classes, but instead new, optional parameter for the Config, that is already consumed by them. Default should be false, correct, to retain current behavior. python-pyodata/pyodata/v2/model.py Lines 101 to 104 in 21a99b5 It is the generic issue of specific problem of "Date valid minimum value vs default value" discussed in #143 But additionally, there is another layer of if-else possibilities - it depends also if the service metadata defines the attribute to be Nullable or not - see #102. if the |
25073fa to
0d362a8
Compare
For my use case (copying a 3rd-party database accessible via OData v2 into a SQL database) it is. Also, I think users generally expect to know when a value is missing (null), instead of getting a default value substituted.
I changed the Client to take the (extend) Config object. However, the server does not consume a Config, but a lit of arguments instead. Changing this would break the API.
Fixed it in the latest push. Keeping as draft as I am still fighting the linter and I am unsure about how to document this properly. |
0d362a8 to
9e2eb92
Compare
Codecov Report
@@ Coverage Diff @@
## master #189 +/- ##
==========================================
+ Coverage 92.66% 92.77% +0.11%
==========================================
Files 6 6
Lines 2768 2783 +15
==========================================
+ Hits 2565 2582 +17
+ Misses 203 201 -2
Continue to review full report at Codecov.
|
| .. code-block:: python | ||
|
|
||
| count = getattr(northwind.entity_sets, 'Employees').get_entities().count().execute() | ||
| print(count) |
There was a problem hiding this comment.
The documentation looks good except I am not sure how does the code sample relates to it?
There was a problem hiding this comment.
Not at all 😵💫 - this slipped in by accident and the documentation part is still WIP. Would like to give a "real-world" example using Northwind, just need to find some entity which actually returns a null property.
|
@rettichschnidi How does this change solve #79? Does the reporter need to configure the service instance with |
Empty dates will return Null/None, not the default value.
This and checking if the (nullable) properties are None. |
9e2eb92 to
551ea1f
Compare
551ea1f to
b83823e
Compare
| """OData service""" | ||
|
|
||
| def __init__(self, url, schema, connection): | ||
| def __init__(self, url, schema, connection, retain_null=False): |
There was a problem hiding this comment.
I do not particularly like this API. generic parameters, followed by boolean flag.. it is not much future-proof, when need arise for fifth or sixth configuration parameter in service.
I understand that this is getting quite entangled an messy, because Config class is in the model.py module and so far was not used by service.py at at. And it should in fact be in the root next to client or exceptions, definitely above pyodata/v2, simply because same config parameters should work IMHO in future v4 support as well. Perhaps such move will be in the 2.0.0 version, where backward compatibility can be broken..
But service.py is already at the moment depending on model.py:
python-pyodata/pyodata/v2/service.py
Line 20 in 0599db2
So why not add the config=None to Service, instead of retain_null=False.. and in client.py:72 just pass the same value as in client.py:68
python-pyodata/pyodata/client.py
Line 68 in 0599db2
|
Could you please rebase to the latest master (I don't like merge commits). |
d4dc0a9 to
dfd4b4b
Compare
|
Rebased, using model.Config, improved commit messages and adjusted the documented example to #197. |
| # create service instance based on model we have | ||
| logger.info('Creating OData Service (version: %d)', odata_version) | ||
| service = pyodata.v2.service.Service(url, schema, connection) | ||
| service = pyodata.v2.service.Service(url, schema, connection, config=config) |
Until now, null values received from OData servers get substituted by type specific default values. Users could not differentiate between those substitutes and actual values retrieved by the server, which might coincidentally equal the default ones inserted by pyodata. This commit allows the user to disable the substitution of null values, retrieving a None object instead. Example for Edm.Binary: | Server | pyodata old behavior | pyodata new (retain_null=True) | |--------+----------------------+--------------------------------| | 0 | 0 | 0 | | null | 0 | None |
dfd4b4b to
ff4d60b
Compare
Until now, null values received from a OData server get substituted by a
default value.
Users of this library can not tell apart a value which coincidentally
equals the default, and a missing (null-ed) value received from the
server.
This commit allows the user to disable the substitution of null values by
default values, retrieving a None object instead.
Questions:
In case the maintainers agree with the direction, I will add tests and documentation.(done)