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 return 404 instead of 500 for invalid model class, fixes #570 #1757

Open
wants to merge 1 commit into
base: 2.2
Choose a base branch
from

Conversation

xini
Copy link

@xini xini commented May 28, 2024

Description

When a ModelAdmin is called with a model that doesn’t exist, the fact that it doesn’t exist is exposed in a 500 error if the site is in dev.

Affected: silverstripe/silverstripe-admin 1 and 2 (Silverstripe 4 and 5)

In the init() method of ModelAdmin (https://github.com/silverstripe/silverstripe-admin/blob/2/code/ModelAdmin.php#L165) a RuntimeException is thrown including the class information. This is also the case when there is no user logged into the CMS.

This is the case for v1 and v2 of this module!

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@GuySartorelli
Copy link
Member

GuySartorelli commented May 28, 2024

I'm not convinced this is desirable. As @dhensby points out in the issue, the existing error is useful for debugging. At a minimum I'd want to keep throwing the exception in dev mode.

Maybe we want a 404 in live and maybe test mode? Though I'd want @silverstripe/core-team to weigh in with their thoughts.
In my opinion it's currently working as expected.

@GuySartorelli
Copy link
Member

In the meantime, please retarget this to the 2.2 branch, and either add tests or check the relevant checkbox if tests aren't required.

@michalkleiner
Copy link
Contributor

I'd leave it as is. The fact the model doesn't exist would still be exposed, just with a different HTTP code. It might be more confusing, as a developer, to get 404 instead of 500.

@xini
Copy link
Author

xini commented May 28, 2024

I disagree. When an URL is incorrect, like https://www.silverstripe.org/foo, you expect a 404. This should also be the case for a model admin URL like https://www.silverstripe.org/admin/my-admin/foo. There is no logical reason for this to be a 5xx response and not a 404.

@xini xini force-pushed the pull-modeladmin-invalid-model-class branch from 5493a28 to 20ab93f Compare May 28, 2024 05:53
@xini xini changed the base branch from 2 to 2.2 May 28, 2024 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants