ashb commented on code in PR #46827:
URL: https://github.com/apache/airflow/pull/46827#discussion_r1967701783
##########
airflow/api_fastapi/core_api/datamodels/log.py:
##########
@@ -16,11 +16,29 @@
# under the License.
from __future__ import annotations
-from pydantic import BaseModel
+from datetime import datetime
+from typing import Annotated
+
+from pydantic import BaseModel, ConfigDict, WithJsonSchema
+
+
+class StructuredLogMessage(BaseModel):
+ """An individual log message."""
+
+ # Not every message has a timestamp.
+ timestamp: Annotated[
+ datetime | None,
+ # Schema level, say this is always a datetime if it exists
+ WithJsonSchema({"type": "string", "format": "date-time"}),
Review Comment:
This `WithJsonSchema` makes the schema an accurate representation of what we
actually send is why.
`{"timestamp": "2025-02-24T14:04:03"}`
`{}`
are both allowed but
`{"timestamp": null}`
is not.
The risk of it getting out of sync is minimal -- it's on the next line. Yes,
if the code tried to send a None it would return an error.
> Anyway we needed that at other places and we chose not to manually
override the generated json.
Such as? Why did you choose not to override it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]