From a8cb110ca00c7febb305c4f9dc73baf804e00b04 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:19:38 +1300 Subject: [PATCH 01/12] Amend validation error --- ocpp/messages.py | 11 +++++++---- tests/test_messages.py | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index 5d6012869..df1177345 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -13,7 +13,6 @@ from ocpp.exceptions import ( FormatViolationError, - NotImplementedError, OCPPError, PropertyConstraintViolationError, ProtocolError, @@ -217,10 +216,14 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non validator = get_validator( message.message_type_id, message.action, ocpp_version ) - except (OSError, json.JSONDecodeError): - raise NotImplementedError( - details={"cause": f"Failed to validate action: {message.action}"} + except OSError: + raise ValidationError( + details={"cause": f"JSON validation schema not found for action: {message.action}"} ) + except json.JSONDecodeError: + raise ValidationError( + details={"cause": f"Error in decoding JSON validation schema for action: {message.action}"} + ) try: validator.validate(message.payload) diff --git a/tests/test_messages.py b/tests/test_messages.py index 60c798b0a..4b94d8200 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -6,7 +6,6 @@ from ocpp.exceptions import ( FormatViolationError, - NotImplementedError, PropertyConstraintViolationError, ProtocolError, TypeConstraintViolationError, @@ -240,7 +239,7 @@ def test_validate_payload_with_non_existing_schema(): payload={"invalid_key": True}, ) - with pytest.raises(NotImplementedError): + with pytest.raises(ValidationError): validate_payload(message, ocpp_version="1.6") From e3a9f4c4d4a2a32e5c7da6b6f695f97490b6af43 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:27:25 +1300 Subject: [PATCH 02/12] Fix linting --- ocpp/messages.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index df1177345..802285833 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -218,11 +218,15 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non ) except OSError: raise ValidationError( - details={"cause": f"JSON validation schema not found for action: {message.action}"} + details={ + "cause": f"JSON validation schema not found for action: {message.action}" + } ) except json.JSONDecodeError: raise ValidationError( - details={"cause": f"Error in decoding JSON validation schema for action: {message.action}"} + details={ + "cause": f"Error in decoding JSON validation schema for action: {message.action}" + } ) try: From aeb5553454942cd8078545bae35dea9bb342f613 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:29:36 +1300 Subject: [PATCH 03/12] Fix linting --- ocpp/messages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index 802285833..e2cfba0b6 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -223,11 +223,11 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non } ) except json.JSONDecodeError: - raise ValidationError( + raise ValidationError( details={ "cause": f"Error in decoding JSON validation schema for action: {message.action}" } - ) + ) try: validator.validate(message.payload) From daaa31d6156ac4b17efb2e45d33c7de1a51333bc Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:31:52 +1300 Subject: [PATCH 04/12] Fix linting --- ocpp/messages.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index e2cfba0b6..51b3d7741 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -219,13 +219,15 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non except OSError: raise ValidationError( details={ - "cause": f"JSON validation schema not found for action: {message.action}" + "cause": f"JSON validation schema not found " + "for action: {message.action}" } ) except json.JSONDecodeError: raise ValidationError( details={ - "cause": f"Error in decoding JSON validation schema for action: {message.action}" + "cause": f"Error in decoding JSON validation schema " + "for action: {message.action}" } ) From 4f616d8892d3a181077113367b83287c52a2d453 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:35:29 +1300 Subject: [PATCH 05/12] Fix linting --- ocpp/messages.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index 51b3d7741..53f3d4707 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -220,14 +220,14 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non raise ValidationError( details={ "cause": f"JSON validation schema not found " - "for action: {message.action}" + f"for action: {message.action}" } ) except json.JSONDecodeError: raise ValidationError( details={ "cause": f"Error in decoding JSON validation schema " - "for action: {message.action}" + f"for action: {message.action}" } ) From 77ebac69f169afffca57c33f22f03e308548554b Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:41:03 +1300 Subject: [PATCH 06/12] Fix error args --- ocpp/messages.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index 53f3d4707..c3ce5968c 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -218,17 +218,13 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non ) except OSError: raise ValidationError( - details={ - "cause": f"JSON validation schema not found " - f"for action: {message.action}" - } + f"JSON validation schema not found " + f"for action: {message.action}" ) except json.JSONDecodeError: raise ValidationError( - details={ - "cause": f"Error in decoding JSON validation schema " - f"for action: {message.action}" - } + f"Error in decoding JSON validation schema " + f"for action: {message.action}" ) try: From 6e485b6dc298697c2755c6a8ae36ea1556d23169 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Fri, 3 Nov 2023 23:42:44 +1300 Subject: [PATCH 07/12] Fix linting --- ocpp/messages.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index c3ce5968c..93183cfb4 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -218,13 +218,11 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non ) except OSError: raise ValidationError( - f"JSON validation schema not found " - f"for action: {message.action}" + f"JSON validation schema not found for action: {message.action}" ) except json.JSONDecodeError: raise ValidationError( - f"Error in decoding JSON validation schema " - f"for action: {message.action}" + f"Error in decoding JSON validation schema for action: {message.action}" ) try: From be242ecc88bd26bf8b9a41e9de6fe75bfe99cb9f Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Tue, 7 Nov 2023 22:44:58 +1300 Subject: [PATCH 08/12] Include error chain --- ocpp/messages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ocpp/messages.py b/ocpp/messages.py index 93183cfb4..d45a2e41d 100644 --- a/ocpp/messages.py +++ b/ocpp/messages.py @@ -216,14 +216,14 @@ def validate_payload(message: Union[Call, CallResult], ocpp_version: str) -> Non validator = get_validator( message.message_type_id, message.action, ocpp_version ) - except OSError: + except OSError as e: raise ValidationError( f"JSON validation schema not found for action: {message.action}" - ) - except json.JSONDecodeError: + ) from e + except json.JSONDecodeError as e: raise ValidationError( f"Error in decoding JSON validation schema for action: {message.action}" - ) + ) from e try: validator.validate(message.payload) From eeccb507bed59a3bafcae2cf7c988d50c9131bd0 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Thu, 16 Nov 2023 10:44:22 +1300 Subject: [PATCH 09/12] Update changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6cd7bf26..532076859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,13 @@ # Change log - +- [#506](https://github.com/mobilityhouse/ocpp/issues/506) Reduce use of NotSupportedError in favor of ValidationError when validating payload. Thanks [@drc38](@https://github.com/drc38). - [#510](https://github.com/mobilityhouse/ocpp/issues/510) v2.0.1 UnitOfMeasureType - Enums missing and update docstring to allow use for variableCharacteristics - [#508](https://github.com/mobilityhouse/ocpp/issues/508) Exception - OccurrenceConstraintViolationError doc string correction ## 0.22.0 (2023-11-03) -- [#493](https://github.com/mobilityhouse/ocpp/issues/493) Reduce use of NotSupportedError in favor of NotImplementedError. Thanks [drc38](@https://github.com/drc38). +- [#493](https://github.com/mobilityhouse/ocpp/issues/493) Reduce use of NotSupportedError in favor of NotImplementedError. Thanks [@drc38](@https://github.com/drc38). - [#278](https://github.com/mobilityhouse/ocpp/pull/278) Fix types for attributes of OCPP 1.6's type `IdTagInfo`. Thanks [@chan-vince](https://github.com/chan-vince) - [#504](https://github.com/mobilityhouse/ocpp/pull/504) Add missing tech_info attribute to v2.0.1 EventDataType. Thanks [@LokiHokie](https://github.com/LokiHokie) - [#381](https://github.com/mobilityhouse/ocpp/issues/381) Add FormationError and OccurrenceConstraintViolationError. From 20f9079dd2b5f773c6d23a5d7f0b06ae6dbcbf18 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:59:54 +1300 Subject: [PATCH 10/12] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6851bbb..27b3ece45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,7 +104,6 @@ ## 0.22.0 (2023-11-03) -- [#493](https://github.com/mobilityhouse/ocpp/issues/493) Reduce use of NotSupportedError in favor of NotImplementedError. Thanks [@drc38](@https://github.com/drc38). - [#278](https://github.com/mobilityhouse/ocpp/pull/278) Fix types for attributes of OCPP 1.6's type `IdTagInfo`. Thanks [@chan-vince](https://github.com/chan-vince) - [#504](https://github.com/mobilityhouse/ocpp/pull/504) Add missing tech_info attribute to v2.0.1 EventDataType. Thanks [@LokiHokie](https://github.com/LokiHokie) - [#381](https://github.com/mobilityhouse/ocpp/issues/381) Add FormationError and OccurrenceConstraintViolationError. From a829ad8b2950c64022f6f92f01326571a1a70642 Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:07:55 +1300 Subject: [PATCH 11/12] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b3ece45..7c7aeaf17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change log -- [#506](https://github.com/mobilityhouse/ocpp/issues/506) Reduce use of NotSupportedError in favor of ValidationError when validating payload. Thanks [@drc38](@https://github.com/drc38). +- [#506](https://github.com/mobilityhouse/ocpp/pull/506) Replace NotImplementedError with ValidationError when an OSError occurs. Thanks [drc38](@https://github.com/drc38). ## 2.0.0-rc.2 (2024-06-18) @@ -104,6 +104,7 @@ ## 0.22.0 (2023-11-03) +- [#493](https://github.com/mobilityhouse/ocpp/issues/493) Reduce use of NotSupportedError in favor of NotImplementedError. Thanks [drc38](@https://github.com/drc38). - [#278](https://github.com/mobilityhouse/ocpp/pull/278) Fix types for attributes of OCPP 1.6's type `IdTagInfo`. Thanks [@chan-vince](https://github.com/chan-vince) - [#504](https://github.com/mobilityhouse/ocpp/pull/504) Add missing tech_info attribute to v2.0.1 EventDataType. Thanks [@LokiHokie](https://github.com/LokiHokie) - [#381](https://github.com/mobilityhouse/ocpp/issues/381) Add FormationError and OccurrenceConstraintViolationError. From ac0348fa59b4d4d8e3b22d4f4757cfbece728b4d Mon Sep 17 00:00:00 2001 From: drc38 <20024196+drc38@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:13:55 +1300 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58a468976..0443ac90a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Change log - + ## 2.0.0-rc.3 (2024-12-09) - [#665](https://github.com/mobilityhouse/ocpp/pull/665) chore: Updated Python setup action to version v5 by @jainmohit2001 - [#663](https://github.com/mobilityhouse/ocpp/pull/663) bugfix: Changed total_cost type from Optional[int] to Optional[float] by @jainmohit2001