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

Navigating to resource detail page causes 404 when resource uses large id as string #5527

Closed
nhaynes opened this issue May 12, 2023 · 6 comments
Assignees
Labels
bug Verified bug by the Nova team

Comments

@nhaynes
Copy link

nhaynes commented May 12, 2023

  • Laravel Version: 9.52.7
  • Nova Version: 4.24.0
  • PHP Version: 8.1.16
  • Database Driver & Version: Mysql
  • Operating System and Version: Ubuntu 22.04.1
  • Browser type and version: Google Chrome 112.0.5615.165
  • Reproduction Repository: https://github.com/nhaynes/nova-issue-5527

Description:

We have some models where we are using Snowflake IDs instead of the standard integer ids. The implementation is pretty much the same as the HasUuids option that ships with Laravel but instead of Uuids, you get snowflake ids.

This has been working well for us with Nova until the 4.24.0 update. It seems a change in that release started casting our snowflake IDs as integers and so a Snowflake ID like 171392037059436224 becomes 171392037059436220 once the value is supplied to the Vue front-end. This in turn breaks the links to our resource detail pages because it's the wrong id.

We've run into this ourselves and so we treat our snowflake IDs as strings in PHP and javascript code:

    /**
     * Casts the Snowflake ID as a string.
     */
    protected function id(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => (string) $value,
            set: fn ($value) => (int) $value,
        );
    }

I did some digging around in the vendor folder I believe it's line 57 in the Util.php file that is causing the problem.

Detailed steps to reproduce the issue on a fresh Nova installation:

  • Create a Model and override the ID so it returns the id s a string
  • Create a Model record with the id 171392037059436224
  • Create a Nova resource for that model and view 171392037059436220 as the ID
@crynobone
Copy link
Member

Can you provide a reproducing repository for this issue? and are you specify the model key type attribute to string?

@crynobone crynobone added the needs more info More information is required label May 12, 2023
@nhaynes
Copy link
Author

nhaynes commented May 12, 2023

Here is the reproducing repository: https://github.com/nhaynes/nova-issue-5527

@crynobone crynobone removed the needs more info More information is required label May 12, 2023
@crynobone crynobone self-assigned this May 12, 2023
@crynobone crynobone added the bug Verified bug by the Nova team label May 12, 2023
@nhaynes
Copy link
Author

nhaynes commented May 12, 2023

I tried making use of asBigInt on the ID::make() field and that appears to fix the issue for the ID field but if you make any references to that Resource using a BelongsTo the problem occurs on those BelongsTo fields and results in a 404.

@nhaynes
Copy link
Author

nhaynes commented May 15, 2023

@davidhemphill Will this fix be in the next release then?

@crynobone
Copy link
Member

Will be available on the upcoming release.

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

2 participants