Skip to content

[10.x] ClientFactory breaks when using UUIDs and quiet creation #1491

@axlon

Description

@axlon
  • Passport Version: 10.1.3
  • Laravel Version: 8.63.0
  • PHP Version: 8.0.10
  • Database Driver & Version: n/a

Description:

Laravel 8.59 introduced the ability to create models quietly (without events) using model factories. Because Laravel Passport currently uses a model event listener to set a UUID on the Client model, Passport's model factory will fail to create client models when using both quiet creation and the UUIDs option.

Example error:

Integrity constraint violation: 19 NOT NULL constraint failed: oauth_clients.id (SQL: insert into "oauth_clients" ("user_id", "name", "secret", "redirect", "personal_access_client", "password_client", "revoked", "updated_at", "created_at") values (?, Broekenmagazijn, $2y$10$SJO8Kazjw5qFI6gGkST81O1AJT7hsqBMS71CqdA/INkFDdHXkO1Je, http://www.dewit.com/perspiciatis-accusantium-voluptas-esse-aut-debitis-officia-velit, 0, 0, 0, 2021-10-15 07:41:31, 2021-10-15 07:41:31)

Steps To Reproduce:

  • Clone this demo repository
  • Run Composer install and create an .env file
  • Run PHPUnit (its configured to use in-memory database), you should see the error immediately

Possible fixes:

One way to address this would be to move the UUID check out of the model event listener and into the ClientFactory and ClientCommand. This would make Passport's client model behave like any other model that has a non-incremental primary key, in that you would always have to explicitly define it before inserting the model into the database. I propose making this change on master as people might be relying on current behaviour in their applications.

Another solution could be to build a fallback into the model factory, by leaving the model event listener as it is and also adding the check to the model factory. This would have the added benefit of being a non-breaking change (as far as I can tell), but the downside of having the same check in two places.

I'm able to make a PR for either change (or another fix) if any are deemed necessary/acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions