I'm trying to use datetimes in a dataclass as inpu...
# flytekit
s
I'm trying to use datetimes in a dataclass as input to a workflow like this:
Copy code
@dataclass_json
@dataclass
class TrainingArgs:
  latest_timestamps: List[datetime.datetime] = field(default_factory=lambda: [])
But now I'm getting a schema warning (I haven't tried to run it yet):
Copy code
{
  "asctime": "2023-03-15 15:13:19,393",
  "name": "flytekit",
  "levelname": "WARNING",
  "message": "Failed to extract schema for object <class 'TrainingArgs'>, (will run schemaless) error: unsupported field type <fields._TimestampField(dump_default=datetime.datetime(2023, 3, 15, 15, 13, 19, 383752), attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.'})>If you have postponed annotations turned on (PEP 563) turn it off please. Postponedevaluation doesn't work with json dataclasses"
}
Does anyone have an idea how to get this working?
k
Try
Copy code
latest_timestamps: typing.List[datetime.datetime] = field(metadata=config(mm_field=fields.List(fields.DateTime())))
s
Thanks @Kevin Su that's working great. I think I'm still confused sometimes by the fact that dataclasses are converted to JSON instead of "native" Literals like top-level Parameters.
For reference, here's full example in the
dataclasses_json
docs: https://lidatong.github.io/dataclasses-json/#extending
153 Views