Skip to content

find alternative to assertion statements which is more graceful #7728

@deanmcginndm

Description

@deanmcginndm

Checklist

  • [Y] I have verified that that issue exists against the master branch of Django REST framework.
  • [Y] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [Y] This is not a usage question. (Those should be directed to the discussion group instead.)
  • [Y] This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • [Y] I have reduced the issue to the simplest possible case.
  • [N] I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

write a simple model, serialiser, viewset and add it into the urls of the django app, using the default router

class Book(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publication_date = models.DateField()

class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)
    email = models.EmailField()

add a second model, serialiser, viewset which is related to the first, like Book -> Author (primary key relationship) and add it to the urls of the django app, using the default router
on your serialiser, we want to display this field as a url that the browsable API will render with another view so we will use the HyperlinkRelatedField serialiser and provide the view_name as "api:book-detail" and allow a moment for django to reload the application then the queryset as Book.objects.all()

this results in the assertion error freezing the reload, so for example a project in a docker environment doesn't auto-reload and the developer must restart or in some cases even rebuild the container entirely

Expected behavior

between adding the view_name and queryset kwargs, django should reload the application due to changes in a file within the project directory being made

Actual behavior

assertion error is raised and subsequent changes dont trigger auto reloading of the application, and the subsequent changes which will resolve the assertion error

A solution would be to raise an improperly configured error, which would allow the reload to be triggered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions