Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(text2image): Return providers as indexed array #42377

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

marcelklehr
Copy link
Member

Checklist

@marcelklehr
Copy link
Member Author

/backport to stable28

Signed-off-by: MB-Finski <sami.finnila@gmail.com>
Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Why? Is there code relying on this? If so, please update the OCP return type accordingly in phpdoc to indicate array<int,IProvider> or list<IProvider> depending on what is needed.

[EDIT] Reading the referenced issue, you would need list<IProvider> to be sure that you can use key 0 without issue.

@MB-Finski
Copy link
Contributor

Why? Is there code relying on this? If so, please update the OCP return type accordingly in phpdoc to indicate array<int,IProvider> or list<IProvider> depending on what is needed.

The runOrScheduleTask assumes an indexed array with [0] being defined. This causes issues if a user has not specified the default provider and getPreferredProviders returns the unfiltered results of the getProviders() as it currently does. This seemed like the easiest place to fix this.

Signed-off-by: MB-Finski <sami.finnila@gmail.com>
@MB-Finski
Copy link
Contributor

MB-Finski commented Dec 20, 2023

@come-nc I hope I got it right. (I'm essentially a php newbie).

EDIT: Nope, made it worse according to psalm.

@marcelklehr
Copy link
Member Author

Can't we just keep IProvider[]?

@come-nc
Copy link
Contributor

come-nc commented Dec 21, 2023

Can't we just keep IProvider[]?

You can but then calling code cannot assume that index 0 will be populated as the keys can be anything.

@marcelklehr
Copy link
Member Author

Ah, I kind of assumed string[] to be a list, but it's a array<array-key, string> 🙈

@come-nc
Copy link
Contributor

come-nc commented Dec 21, 2023

To fix psalm the property needs to be typed as list as well on https://github.com/nextcloud/server/blob/fix/text-to-image-manager/lib/private/TextToImage/Manager.php#L53

@come-nc
Copy link
Contributor

come-nc commented Dec 21, 2023

Ah, I kind of assumed string[] to be a list, but it's a array<array-key, string> 🙈

Yeah, list forces indexes to be contiguous so you cannot unset in the middle without reindexing, it’s restrictive to it’s not the default type.

@@ -83,7 +83,7 @@ public function getProviders(): array {
foreach ($context->getTextToImageProviders() as $providerServiceRegistration) {
$class = $providerServiceRegistration->getService();
try {
$this->providers[$class] = $this->serverContainer->get($class);
$this->providers[] = $this->serverContainer->get($class);
Copy link
Member

Choose a reason for hiding this comment

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

lib/private/TextToImage/Manager.php:94:10: LessSpecificReturnStatement: The type 'list<mixed>' is more general than the declared return type 'list<OCP\TextToImage\IProvider>' for OC\TextToImage\Manager::getProviders (see https://psalm.dev/129)

Need to adjust the docs on the definition of the member as well

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
@nickvergessen nickvergessen merged commit c4d233a into master Jan 10, 2024
47 of 50 checks passed
@nickvergessen nickvergessen deleted the fix/text-to-image-manager branch January 10, 2024 08:28
@backportbot-nextcloud
Copy link

The backport to stable28 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable28
git pull origin stable28

# Create the new backport branch
git checkout -b fix/foo-stable28

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123

# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable28

Error: Unknown error

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish backport-request bug labels Jan 15, 2024
@blizzz blizzz mentioned this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish backport-request bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined array key 0 at /var/www/nextcloud/lib/private/TextToImage/Manager.php#231
5 participants