Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid empty array to be saved in published_by field - #8970

Open
j0k3r wants to merge 2 commits into
2.6from
fix/avoid-empty-array-published-by
Open

Avoid empty array to be saved in published_by field#8970
j0k3r wants to merge 2 commits into
2.6from
fix/avoid-empty-array-published-by

Conversation

@j0k3r

@j0k3r j0k3r commented Jul 24, 2026

Copy link
Copy Markdown
Member

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.

Fix #8935

@j0k3r j0k3r added this to the 2.6.15 milestone Jul 24, 2026
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.
@j0k3r
j0k3r force-pushed the fix/avoid-empty-array-published-by branch from 26cb055 to 41aeb5b Compare July 24, 2026 15:04
@j0k3r
j0k3r requested review from Kdecherf, nicosomb and yguedidi July 24, 2026 15:24
nicosomb
nicosomb previously approved these changes Jul 24, 2026
Comment thread src/Wallabag/ApiBundle/Controller/EntryRestController.php Outdated
Comment on lines +925 to +933
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
));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks weird to e to have this logic in the entity, shouldn't it be done before we set the value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As setPublishedBy is used in 3 differents places, I thought it should be the best place

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 yguedidi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't a migration be added to clean the DB from bad values?

@j0k3r

j0k3r commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

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.
Otherwise I must target the master branch.

@yguedidi

Copy link
Copy Markdown
Contributor

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?

@nicosomb

Copy link
Copy Markdown
Member

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.

@yguedidi

Copy link
Copy Markdown
Contributor

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 yguedidi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added few answers to comments

@Kdecherf

Copy link
Copy Markdown
Member

@yguedidi @j0k3r generally speaking we avoid pushing database migrations in patch versions because it may require restoring from a backup in case of an upgrade issue.

In this case it should be possible to provide a straightforward down() path for a rollback, maybe we can go ahead and include it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants