Bug Description
The datetime module is added to the simpleeval functions dict in CustomStreamMap.functions (mapper.py line 322), but it is not added to the names dict in _eval(). This means expressions like datetime.datetime.utcnow().isoformat() fail with:
simpleeval.AttributeDoesNotExist: Attribute 'datetime' does not exist in expression 'datetime.datetime.utcnow().isoformat()'
In simpleeval, entries in functions are only invocable as name(args) — they do not support attribute/dot access. Attribute access requires the entry to be in the names dict.
Expected Behavior
As documented in the Inline Stream Maps docs, the datetime module should be usable in expressions with attribute access:
stream_maps:
mystream:
loaded_at: "datetime.datetime.utcnow().isoformat()"
create_year: "int(datetime.date.fromisoformat(create_date).year)"
The SDK's own type detection logic in _get_type() also explicitly expects these patterns to work:
# mapper.py lines 419-425
if expr.startswith(("datetime.date.", "datetime.date(")) or expr.endswith(".date()"):
return th.DateType()
if expr.startswith(("datetime.datetime.", "datetime.datetime(")):
return th.DateTimeType()
Suggested Fix
Add datetime to the names dict in _eval(), alongside record, config, etc.:
names["datetime"] = datetime
(And similarly for json if it has the same issue.)
Environment
- singer-sdk version: 0.53.5 (latest)
- Python version: 3.12
Bug Description
The
datetimemodule is added to the simpleevalfunctionsdict inCustomStreamMap.functions(mapper.py line 322), but it is not added to thenamesdict in_eval(). This means expressions likedatetime.datetime.utcnow().isoformat()fail with:In simpleeval, entries in
functionsare only invocable asname(args)— they do not support attribute/dot access. Attribute access requires the entry to be in thenamesdict.Expected Behavior
As documented in the Inline Stream Maps docs, the
datetimemodule should be usable in expressions with attribute access:The SDK's own type detection logic in
_get_type()also explicitly expects these patterns to work:Suggested Fix
Add
datetimeto thenamesdict in_eval(), alongsiderecord,config, etc.:(And similarly for
jsonif it has the same issue.)Environment