From 4d5d7da95b02e2b80cfd731d45e418c177a55520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 27 Sep 2023 08:15:31 +0200 Subject: [PATCH 1/3] Fix: Mark repo model properties for security and analysis as optional Despite the JSON schema doesn't mention the properties are optional it seems they are actually optional. The property `advanced_security` is missing in several of our responses and therefore we got a model error. --- pontos/github/models/organization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pontos/github/models/organization.py b/pontos/github/models/organization.py index ec6a96a4..5f937aa0 100644 --- a/pontos/github/models/organization.py +++ b/pontos/github/models/organization.py @@ -272,9 +272,9 @@ class SecurityAndAnalysis(GitHubModel): Protection is used """ - advanced_security: SecurityAndAnalysisType - secret_scanning: SecurityAndAnalysisType - secret_scanning_push_protection: SecurityAndAnalysisType + advanced_security: Optional[SecurityAndAnalysisType] = None + secret_scanning: Optional[SecurityAndAnalysisType] = None + secret_scanning_push_protection: Optional[SecurityAndAnalysisType] = None @dataclass From 14c796d192487e85de4287a7fdbd76fa232dc13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 27 Sep 2023 08:16:56 +0200 Subject: [PATCH 2/3] Add: Add repo model property for enabled dependabot security updates The status is missing in our model. Maybe it was added later on. --- pontos/github/models/organization.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pontos/github/models/organization.py b/pontos/github/models/organization.py index 5f937aa0..9cff9155 100644 --- a/pontos/github/models/organization.py +++ b/pontos/github/models/organization.py @@ -267,12 +267,15 @@ class SecurityAndAnalysis(GitHubModel): Attributes: advanced_security: Status of GitHub Advanced Security is used + dependabot_security_updates: Status of Dependabot security updates are + used secret_scanning: Status of Secret Scanning is used secret_scanning_push_protection: Status of Secret Scanning Push Protection is used """ advanced_security: Optional[SecurityAndAnalysisType] = None + dependabot_security_updates: Optional[SecurityAndAnalysisType] = None secret_scanning: Optional[SecurityAndAnalysisType] = None secret_scanning_push_protection: Optional[SecurityAndAnalysisType] = None From c68116952f31e5aa68c1959ad1389c855f764a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 27 Sep 2023 08:18:37 +0200 Subject: [PATCH 3/3] Change: Improve error message when a model value can't be set Make the error message more precise in what's wrong here actually. --- pontos/models/__init__.py | 4 ++-- tests/models/test_models.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pontos/models/__init__.py b/pontos/models/__init__.py index 4c40f505..617a81ce 100644 --- a/pontos/models/__init__.py +++ b/pontos/models/__init__.py @@ -163,8 +163,8 @@ def from_dict(cls, data: Dict[str, Any]): value = cls._get_value(model_field_cls, value) # type: ignore # pylint: disable=line-too-long # noqa: E501 except TypeError as e: raise ModelError( - f"Error while creating {cls.__name__}. Could not set value " - f"for '{name}' from '{value}'." + f"Error while creating {cls.__name__} model. Could not set " + f"value for property '{name}' from '{value}'." ) from e if name in type_hints: diff --git a/tests/models/test_models.py b/tests/models/test_models.py index 64bc7f1b..69e62c50 100644 --- a/tests/models/test_models.py +++ b/tests/models/test_models.py @@ -205,7 +205,7 @@ class ExampleModel(Model): with self.assertRaisesRegex( ModelError, - "Error while creating ExampleModel. Could not set value for 'foo' " - "from '{'bar': 'baz'}'.", + "Error while creating ExampleModel model. Could not set value for " + "property 'foo' from '{'bar': 'baz'}'.", ): ExampleModel.from_dict({"foo": {"bar": "baz"}})