Bug 56399 - Pydantic update breaks class ListenerFileAttributeError
Pydantic update breaks class ListenerFileAttributeError
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: ucsschool-id-connector
UCS@school 5.0
Other Linux
: P5 major (vote)
: ---
Assigned To: Daniel Tröder
Tobias Wenzel
https://git.knut.univention.de/univen...
:
Depends on: 56097 56265
Blocks:
  Show dependency treegraph
 
Reported: 2023-08-03 15:17 CEST by Johannes Königer
Modified: 2023-08-21 12:20 CEST (History)
9 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 1: Will affect a very few installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.143
Enterprise Customer affected?:
School Customer affected?: Yes
ISV affected?:
Waiting Support: Yes
Flags outvoted (downgraded) after PO Review:
Ticket number: 2023080221000104
Bug group (optional): Regression
Max CVSS v3 score: 7.5


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Königer univentionstaff 2023-08-03 15:17:50 CEST
+++ This bug was initially created as a clone of Bug #56265 +++

+++ This bug was initially created as a clone of Bug #56097 +++

With Bug #56265 and commit https://git.knut.univention.de/univention/components/ucsschool-id-connector/-/commit/f585e9b06b9b314de65b1a96fbaa51aacdbb4ca5 `pydantic` was updated:

```
-pydantic[ujson,email]==0.32.2
+pydantic[ujson,email]>=1.10.9,<1.11.0
```

The `PydanticErrorMixin` class changed with the following commit, which happened somewhere between 0.32.2 and 1.10.9:

https://github.com/pydantic/pydantic/commit/24ac05276bdb9d97b57e65ab37672a38bfbde711#diff-a9fb7aabd1a5225682c2fe6ecaee290b3376ccb37543d854851b5be607ba9d06L8-L18

The `__dict__` attribute of instances of `PydanticErrorMixin` are now overwritten by the `__init__` method with keyword argument dictionary.
The `ListenerFileAttributeError` inherits from `PydanticValueError` which in turn inherits from `PydanticErrorMixin`.
The update broke the initialization of `ListenerFileAttributeError`, `msg_template` and `code` are no longer set, and it then falls back to the class attributes.
This results in confusing and wrong error output.

In `ListenerFileAttributeError` we now no longer need to set the attributes `code` and `msg_template` attributes and can rely on the super class from pydantic to do that for us. This should fix the bug:

```
diff --git a/src/ucsschool_id_connector/models.py b/src/ucsschool_id_connector/models.py
index 7269b8d..e210976 100644
--- a/src/ucsschool_id_connector/models.py
+++ b/src/ucsschool_id_connector/models.py
@@ -50,17 +50,6 @@ class ListenerFileAttributeError(PydanticValueError):
     code = "invalid_listener_file"
     msg_template = 'Missing or empty value in listener file: "{key}"="{value}"'
 
-    def __init__(self, *args, **kwargs):
-        try:
-            self.code = kwargs.pop("code")
-        except KeyError:
-            pass
-        try:
-            self.msg_template = kwargs.pop("msg_template")
-        except KeyError:
-            pass
-        super().__init__(*args, **kwargs)
-
 
 class MissingArgumentError(PydanticValueError):
     code = "missing_argument"
```
Comment 1 Erik Damrose univentionstaff 2023-08-03 15:24:25 CEST
An issue in a customer environment was, that the msg_template and code attributes were overwritten by the super().__init__() call. A plugin working with those values stopped working. No new users could be provisioned.
Comment 3 Tobias Wenzel univentionstaff 2023-08-21 12:20:34 CEST
Updates for UCS@school ID Connector 2.2.8 have been released.

    https://docs.software-univention.de/ucsschool-id-connector/HISTORY.html

If this error occurs again, please clone this bug.