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

Add arg skip_schema_validation to @on() #56

Merged
merged 2 commits into from
Dec 3, 2019
Merged

Conversation

OrangeTux
Copy link
Contributor

The argument can be used to skip validation of a request and response.
It defaults to False, so by default validation is enabled.

The reasoning for this change is that TMH has charge points which use
measurands inside MeterValues messages which are not compliant with the
OCPP 1.6 specification. Therefore the validation of these messages fail.

With this new argument validation of certain messages can be disabled.

Fixes: #54

@ghost
Copy link

ghost commented Dec 3, 2019

DeepCode Report (#e4122f)

DeepCode analyzed this pull request.
There are 3 new info reports.

The argument can be used to skip validation of a request and response.
It defaults to `False`, so by default validation is enabled.

The reasoning for this change is that TMH has charge points which use
measurands inside MeterValues messages which are not compliant with the
OCPP 1.6 specification. Therefore the validation of these messages fail.

With this new argument validation of certain messages can be disabled.

Fixes: #54
@OrangeTux OrangeTux force-pushed the 54-disable-validation branch from 43c6551 to 41479e7 Compare December 3, 2019 11:08
@@ -1,7 +1,7 @@
import functools


def on(action):
def on(action, *, skip_schema_validation=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where does the asterisk come into play?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All arguments after the aterisk can only used with as keyword arguments.

So the following call would raise a TypeError:

def foo(*, a):
    pass

foo(1)  # will raise a TypeError

Instead it is required to use keyword arguments:

foo(a=1)  # works fine

Without aterisk the @on() decorator could be used like this:

@on("MeterValues", True)
def on_meter_values(*args, **kwargs):
   pass

Without the keyword it is hard to guess what the meaning is of the second argument. I added the aterisk to make it explicit to disable validation. You can either use skip_schema_validations default value of False. Or, if you want to disable the validation, you can set it to true by keyword arguments:

@on("MeterValues", skip_schema_validation=True)
def on_meter_values(*args, **kwargs):
   pass

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. Thanks for the explanation.

@OrangeTux OrangeTux merged commit b06c6ca into master Dec 3, 2019
@OrangeTux OrangeTux deleted the 54-disable-validation branch December 3, 2019 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add option to disable validation against JSON schemas
2 participants