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

pytkdocs/django compatibility issues #149

Open
jmcgill298 opened this issue Oct 27, 2021 · 5 comments
Open

pytkdocs/django compatibility issues #149

jmcgill298 opened this issue Oct 27, 2021 · 5 comments
Labels
unconfirmed This bug was not reproduced yet

Comments

@jmcgill298
Copy link

Please open an issue on pytkdocs instead
if this is related to Python docstrings parsing or the collection of Python objects!

Describe the bug
Having pytkdocs >= 0.12.0 causes mkdocstrings build to crash with Django projects. Installation of pytkdocs with pip installs a version of pytkdocs >= 0.12.0.

To Reproduce
Steps to reproduce the behavior:

  1. pip install mkdocstrings
  2. add mkdocs config to load docstrings for Django project
  3. run mkdocs build cli command
  4. See error

Expected behavior
I expected the docs to be built

Screenshots

nautobot@2f093c201409:~/plugins/nautobot-plugin-device-status-change$ python -m mkdocs build
INFO     -  MERMAID2  - Initialization arguments: {}
INFO     -  MERMAID2  - Using javascript library (8.11.2):
               https://unpkg.com/[email protected]/dist/mermaid.min.js
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /opt/nautobot/plugins/nautobot-plugin-device-status-change/site
ERROR    -  mkdocstrings.extension: 'FilterSetOptions' object has no attribute 'get_fields'
            Traceback (most recent call last):
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/cli.py", line 205, in main
                output = json.dumps(process_json(line))
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/cli.py", line 114, in process_json
                return process_config(json.loads(json_input))
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/cli.py", line 91, in process_config
                obj = loader.get_object_documentation(path, members)
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/loader.py", line 358, in get_object_documentation
                root_object = self.get_module_documentation(leaf, members)
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/loader.py", line 426, in get_module_documentation
                root_object.add_child(self.get_class_documentation(child_node))
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/loader.py", line 519, in get_class_documentation
                child = self.get_class_documentation(child_node)
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/loader.py", line 542, in get_class_documentation
                if self.detect_field_model(attr_name, direct_members, all_members):
              File "/opt/nautobot/.local/lib/python3.6/site-packages/pytkdocs/loader.py", line 577, in detect_field_model
                if remainder and not attrgetter(remainder)(all_members[first_order_attr_name]):
            AttributeError: 'FilterSetOptions' object has no attribute 'get_fields'
ERROR    -  Error reading page 'api/views.md':
ERROR    -  Could not collect 'device_status_change_plugin.views'

Aborted with a BuildError!

Information (please complete the following information):

  • OS: Ubuntu 20.04 WSL2
  • mkdocstrings version: 0.16.2 (tried all since June)
  • pytkdocs version: 0.[12, 13, 14].0 (worked once I got to 0.11.1)

Additional context
Add any other context about the problem here.

@jmcgill298 jmcgill298 added the unconfirmed This bug was not reproduced yet label Oct 27, 2021
@luis-amarquez
Copy link

luis-amarquez commented Oct 31, 2021

I am just a beginner

I am running the same version of pytkdocs and am not having an issue. I am no expert but I do want to try to help.

I had received a similar error or maybe even the same, I am not near my work station right now, but my issue was a bad mkdocs.yml. I had copied the config from somewhere online and produced and error. After checking the mkdocstring documentation, I removed a few lines I had in the handler config. If your handler does not look the same as mine below, that might be the issue.

plugins:
  - search
  - mkdocstrings:
      handlers:
        python:
          setup_commands:
            - import os
            - import sys
            - import django
            - sys.path.insert(0, os.path.abspath('../src/'))
            - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "graphql_api.settings")
            - django.setup()

@jmcgill298 I hope that can be of some help.

@BrayanMota
Copy link

BrayanMota commented Jan 6, 2022

I have the same AttributeError problem, but it's on my form.
AttributeError: 'ModelFormOptions' object has no attribute 'get_fields'
Did you manage to solve the problem?

@pawamoy
Copy link
Member

pawamoy commented Feb 7, 2022

A new Python handler is available and fixes all these AttributeError issues since it does not execute the code anymore, but only parses/visits it. Note however that this new handler is experimental and might not work as you expect, or as the legacy handler does, particularly with third-party libs like Django. Beta-tests and feedback are greatly appreciated! Closing for now, feel free to reopen, or open new issues.

@Skrattoune
Copy link

I have the same AttributeError problem, but it's on my form. AttributeError: 'ModelFormOptions' object has no attribute 'get_fields' Did you manage to solve the problem?

Hi @BrayanMota,
I have exactly the same issue.
The new handler is still not supporting Django, so I'm stuck.
Did you find a solution to bypass those errors (for a class, a function or a whole module) and continue generating the documentation ?

@pawamoy
Copy link
Member

pawamoy commented Aug 2, 2023

If someone is willing to fix this, PRs are welcome in pytkdocs! I'm reopening this and moving the issue to pytkdocs' repo.

@pawamoy pawamoy reopened this Aug 2, 2023
@pawamoy pawamoy transferred this issue from mkdocstrings/mkdocstrings Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed This bug was not reproduced yet
Projects
None yet
Development

No branches or pull requests

5 participants