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

exception: 'str' object has no attribute '_meta' when GenericRelation #43

Open
ntouran opened this issue Aug 16, 2023 · 0 comments
Open
Labels

Comments

@ntouran
Copy link

ntouran commented Aug 16, 2023

If you have a GenericRelation field that uses a deferred string argument rather than an a class argument, documentation build fails with:

Extension error (sphinxcontrib_django.docstrings):
Handler <function improve_docstring at 0x00000123AE286EE0> for event 'autodoc-process-docstring' threw an exception (exception: 'str' object has no attribute '_meta')

Through the debugger, I narrowed the issue down to here, where the format string argument fails because field.model is a string ("app2.ModelB" in the example code below)

https://github.com/edoburu/sphinxcontrib-django/blob/872cb8d56df8d76315a233ba8a2af3d9cce23b1c/sphinxcontrib_django/docstrings/field_utils.py#L83

Example code:

# in app1/models.py
class ModelA(models.Model):
    relation_field = GenericRelation(
        "app2.ModelB",
    )


# in app2/models.py
class ModelB(models.Model):
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField(null=True)
    content_object = GenericForeignKey()

I have a fix incoming that deals with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants