Browse Source

fix(hybrid-cloud): Pushes a temporary fix for pydantic unpickling issues with the v2 upgrade (#75386)

Gabe Villalobos 7 months ago
parent
commit
6b4a60abe9
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/sentry/hybridcloud/rpc/__init__.py

+ 11 - 0
src/sentry/hybridcloud/rpc/__init__.py

@@ -49,6 +49,17 @@ class RpcModel(pydantic.BaseModel):
         from_attributes=True, use_enum_values=True, coerce_numbers_to_str=True
     )
 
+    def __setstate__(self, state: dict[Any, Any]) -> None:
+        """
+        __setstate__ override to alleviate an unpickling issue in production with the pydantic version upgrade.
+        """
+        state.setdefault("__pydantic_extra__", {})
+        state.setdefault("__pydantic_private__", {})
+
+        if "__pydantic_fields_set__" not in state:
+            state["__pydantic_fields_set__"] = state.get("__fields_set__")
+        super().__setstate__(state)
+
     @classmethod
     def get_field_names(cls) -> Iterable[str]:
         return iter(cls.model_fields.keys())