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

[4.x]: \craft\services\Drafts#createDraft should not require integer value for $creatorId argument #11904

Closed
ivanBereznev opened this issue Sep 8, 2022 · 5 comments
Assignees

Comments

@ivanBereznev
Copy link

What happened?

Description

When modifying a draft via GraphQL API, there can be no current user assigned, i.e. Craft::$app->getUser()->getId() returns null. In this case there is no way to assign any valid creatorId so requiring an integer for $creatorId argument does not look completely correct.
In particular this causes failures when modifying Neo block fields with GraphQL.
Probably the issue is on the plugin side, but since there seems to be no way for it to get ID of the current user it seems to me that API from Craft side is inconsistent.

Steps to reproduce

  1. Create an entry with a Neo field
  2. Create a draft for an entry
  3. Try to modify the value of Neo field for the draft using GraphQL API.

Expected behavior

Changes are applied to the draft.

Actual behavior

An exception is thrown:

[TypeError] craft\services\Drafts::createDraft(): Argument #2 ($creatorId) must be of type int, null given, called in /app/vendor/spicyweb/craft-neo/src/Field.php on line 1197

The exception originates from this line where plugin tries to create draft for a block providing ID of the current user which is null.

Craft CMS version

4.2.3

PHP version

8.0

Operating system and version

Debian GNU/Linux 11

Database type and version

PostgreSQL 13.6

Image driver and version

No response

Installed plugins and versions

  • spicyweb/craft-neo : 3.3.7
@ttempleton
Copy link

It's worth noting that Neo fields do this the same way as Matrix and Super Table fields, so I assume this would affect all three field types.

brianjhanson added a commit that referenced this issue Sep 12, 2022
@brianjhanson brianjhanson self-assigned this Sep 12, 2022
@brandonkelly
Copy link
Member

This should be resolved for Craft 4.3 via #11923.

If you’d like to test, change your craftcms/cms constraint in composer.json to 4.3.x-dev#7c232ea3613c779fdaf986a9b90a64f426b1faad as 4.3.0

@ivanBereznev
Copy link
Author

@brandonkelly thank you, we've tested it in dev and it works properly now. Could you please share any timeframe when we can expect Craft 4.3 to be released?

@brandonkelly
Copy link
Member

@ivanBereznev 4.3 will be out by the end of the month.

@brandonkelly
Copy link
Member

Craft 4.3 was released earlier this week!

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

No branches or pull requests

4 participants