| 852 | |
| 853 | |
| 854 | def add_request_id(obj: BaseModel, request_id: str | None) -> None: |
| 855 | obj._request_id = request_id |
| 856 | |
| 857 | class="cm"># in Pydantic v1, using setattr like we do above causes the attribute |
| 858 | class="cm"># to be included when serializing the model which we don't want in this |
| 859 | class="cm"># case so we need to explicitly exclude it |
| 860 | if PYDANTIC_V1: |
| 861 | try: |
| 862 | exclude_fields = obj.__exclude_fields__ class="cm"># type: ignore |
| 863 | except AttributeError: |
| 864 | cast(Any, obj).__exclude_fields__ = {class="st">"_request_id", class="st">"__exclude_fields__"} |
| 865 | else: |
| 866 | cast(Any, obj).__exclude_fields__ = {*(exclude_fields or {}), class="st">"_request_id", class="st">"__exclude_fields__"} |
| 867 | |
| 868 | |
| 869 | class="cm"># our use of subclassing here causes weirdness for type checkers, |