|
| 1 | +import sys |
1 | 2 | import time |
2 | 3 | import unittest |
3 | 4 | from dataclasses import dataclass |
@@ -122,11 +123,29 @@ class NestedModel(BaseModel): |
122 | 123 | "bar": 2, |
123 | 124 | "baz": None, |
124 | 125 | } |
125 | | - assert utils.clean(ModelV1(foo=1, bar="2")) == {"foo": 1, "bar": "2"} |
| 126 | + # Pydantic V1 is not compatible with Python 3.14+ |
| 127 | + if sys.version_info < (3, 14): |
| 128 | + assert utils.clean(ModelV1(foo=1, bar="2")) == {"foo": 1, "bar": "2"} |
126 | 129 | assert utils.clean(NestedModel(foo=ModelV2(foo="1", bar=2, baz="3"))) == { |
127 | 130 | "foo": {"foo": "1", "bar": 2, "baz": "3"} |
128 | 131 | } |
129 | 132 |
|
| 133 | + @unittest.skipIf(sys.version_info < (3, 14), "Test only relevant for Python 3.14+") |
| 134 | + def test_clean_pydantic_v1_warning_on_python_314(self): |
| 135 | + """Verify that Pydantic V1 models emit a warning on Python 3.14+""" |
| 136 | + class ModelV1(BaseModelV1): |
| 137 | + foo: int |
| 138 | + bar: str |
| 139 | + |
| 140 | + with self.assertLogs("posthog", level="WARNING") as cm: |
| 141 | + result = utils.clean(ModelV1(foo=1, bar="2")) |
| 142 | + # V1 models return empty dict on Python 3.14+ |
| 143 | + assert result == {} |
| 144 | + |
| 145 | + # Verify the warning was emitted |
| 146 | + assert len(cm.output) == 1 |
| 147 | + assert "Pydantic V1 models are not compatible with Python 3.14+" in cm.output[0] |
| 148 | + |
130 | 149 | def test_clean_pydantic_like_class(self) -> None: |
131 | 150 | class Dummy: |
132 | 151 | def model_dump(self, required_param: str) -> dict: |
|
0 commit comments