I got the error described on TypeScript code generation and StructuredText value types - #2 by m.finamor but I realized that it is caused by models in my production project having duplicate fields for created and updated at. These fields exist both as createdAt
/updatedAt
and _createdAt
/_updatedAt
.
I cannot replicate this behavior in a new DatoCMS project so I suspect it is related to the project itself, which was created many months ago.
Troubleshooting
I created a new empty model in both the old and a new project.
The problem is possible to see by just looking at the generated documentation for the model in the CDA playground.
In the old project I can see that my new model (model id: OPHSix_CQRq3yFuzP8ehjg
) has these attributes (there are also other attributes but they are the same in the two projects):
_createdAt: DateTime!
_updatedAt: DateTime!
createdAt: DateTime!
updatedAt: DateTime!
But in the new project the model (model id dyNLgLmkQpSynfPKQzcDew
) only the ones prefixed with underscore are present:
_createdAt: DateTime!
_updatedAt: DateTime!
After adding the field name
and creating records for each model and fetching these models via the REST-API I can see that the old project shows createdAt
/updatedAt
under attributes
as well as under meta
while the new project only shows them under meta
:
Old project:
{
"data": {
"id": "bETbOd1qQRaQVF8lAJptGQ",
"type": "item",
"attributes": {
"name": "A record",
"updated_at": "2023-11-24T11:06:08.555+01:00",
"created_at": "2023-11-24T11:06:08.547+01:00"
},
"meta": {
"created_at": "2023-11-24T11:06:08.547+01:00",
"updated_at": "2023-11-24T11:06:08.555+01:00",
…
}
}
…
}
New project:
{
"data": {
"id": "Xd2hXXq4TfuknnSzJn9o5Q",
"type": "item",
"attributes": {
"name": "A record"
},
"meta": {
"created_at": "2023-11-24T10:09:36.048+00:00",
"updated_at": "2023-11-24T10:09:36.057+00:00",
…
}
}
…
}
I thought the error may depend on unapplied updates or plugins so I forked a new environment in the old project, activated all available updates, removed all plugins and recreated the model but with the same result. The model id for this “clean” environment is DNBxQx5tRYWpzF0kYccuKg
and the record id is XqgMroloQZWsuZtCwHhU9A
The only difference left that I can think of is the age of the project itself. Maybe the old project has been grandfathered to use some feature for backwards compatibility reasons? If this is the case, do you plan on making it possible to upgrade this behavior?