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

[#1635]Add model name in DoesNotExist and MultipleObjectsReturned message #1637

Closed
wants to merge 2 commits into from

Conversation

BraveEggTart
Copy link

Description

Add the model.name field to the DoesNotExist and MultipleObjectsReturned exception message to obtain clearer prompts when calling the model. get() method.

Motivation and Context

When I use the Model.get() method and a DoesNotExist exception occurs because there is no corresponding record in the database, the provided error message is often not specific enough for me to quickly identify which Model is involved. The message "Object does not exist" is too generic.

#1635

How Has This Been Tested?

I executed the make test command and passed all tests related to the get() method, such as the test_get method in test_queryset.py.

testing environment: python: 3.10.6

There's something I need to say. I checked the code about DoesNotExist and MultipleObjectsReturned, and noticed that in the _getbypk method of models.py, DoesNotExist was processed and returned cls._meta.full_name, Is this a place that needs to be modified synchronously?

    @classmethod
    async def _getbypk(cls: Type[MODEL], key: Any) -> MODEL:
        try:
            return await cls.get(pk=key)
        except (DoesNotExist, ValueError):
            raise KeyError(f"{cls._meta.full_name} has no object {repr(key)}")

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@abondar
Copy link
Member

abondar commented Jun 3, 2024

Hi!

Sorry for confusion - just merged #742 which did basically the same few hours before
Still hope your problem is resolved by merged change, I will release it as 0.21.4 a little bit later

@abondar abondar closed this Jun 3, 2024
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.

None yet

2 participants