Avoid empty array to be saved in published_by field - #8970
Conversation
Looks like a kind of empty `authors` given from the API can lead to an array of an empty value to be saved in the database. Also, the default value for the `authors` field in the API can generate that problem too.
26cb055 to
41aeb5b
Compare
| if (\is_array($publishedBy)) { | ||
| $publishedBy = array_values(array_filter( | ||
| array_map( | ||
| static fn ($author) => is_scalar($author) ? trim((string) $author) : '', | ||
| $publishedBy | ||
| ), | ||
| static fn ($author) => '' !== $author | ||
| )); | ||
| } |
There was a problem hiding this comment.
looks weird to e to have this logic in the entity, shouldn't it be done before we set the value?
There was a problem hiding this comment.
As setPublishedBy is used in 3 differents places, I thought it should be the best place
There was a problem hiding this comment.
my point is more that none of the existing setters have a logic inside, so I'd preserve that, especially that they are used by Doctrine.
I'd suggest maybe to add a specialized setter, maybe something like setRawPublishedAt(...) or whatever you'll find better. that one then will not be tied to Doctrine, so it can have logic 😉
yguedidi
left a comment
There was a problem hiding this comment.
shouldn't a migration be added to clean the DB from bad values?
I target the 2.6 branch so I can't add a migration here. |
@j0k3r why it's not possible to add a migration on 2.6? |
because it will be a patch version. Migrations will be on minor or major releases. |
I'm not aware of this rule. why is not possible to have migrations on patch versions? I mean, a migration can not be a new feature nor break changes 🙂 |
yguedidi
left a comment
There was a problem hiding this comment.
added few answers to comments
Looks like a kind of empty
authorsgiven from the API can lead to an array of an empty value to be saved in the database. Also, the default value for theauthorsfield in the API can generate that problem too.Fix #8935