pytkdocs
pytkdocs copied to clipboard
pytkdocs/django compatibility issues
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:
- pip install mkdocstrings
- add mkdocs config to load docstrings for Django project
- run
mkdocs buildcli command - 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
mkdocstringsversion: 0.16.2 (tried all since June)pytkdocsversion: 0.[12, 13, 14].0 (worked once I got to 0.11.1)
Additional context Add any other context about the problem here.
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.
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?
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.
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 ?
If someone is willing to fix this, PRs are welcome in pytkdocs! I'm reopening this and moving the issue to pytkdocs' repo.