sphinx-contrib / openapi

OpenAPI (fka Swagger) spec renderer for Sphinx.
https://sphinxcontrib-openapi.readthedocs.io
BSD 2-Clause "Simplified" License
111 stars 81 forks source link

Using gettext_lazy in a django-filter filterset with DRF breaks schema creation #153

Open jeriox opened 8 months ago

jeriox commented 8 months ago

I defined a custom FilterSet class for my DRF viewset. The field in question was defined as from_date = DateTimeFilter(field_name="shift__start_time", lookup_expr="gte", label=_("from")) with from django.utils.translation import gettext_lazy as _. Triggering a sphinx build with this field triggers the error below. When removing it or changing the label to a static string, the build works fine again.

Log:

# Platform:         win32; (Windows-10-10.0.22621-SP0)
# Sphinx version:   7.2.6
# Python version:   3.11.0 (CPython)
# Docutils version: 0.20.1
# Jinja2 version:   3.1.3
# Pygments version: 2.17.2

# Last messages:
#   admin/deployment/manual/index
#   
#   
#   reading sources... [ 21%]
#   admin/index
#   
#   
#   reading sources... [ 24%]
#   api/index
#   

# Loaded extensions:
#   sphinx.ext.mathjax (7.2.6)
#   alabaster (0.7.16)
#   sphinxcontrib.applehelp (1.0.8)
#   sphinxcontrib.devhelp (1.0.6)
#   sphinxcontrib.htmlhelp (2.0.5)
#   sphinxcontrib.serializinghtml (1.1.10)
#   sphinxcontrib.qthelp (1.0.7)
#   sphinxcontrib.jquery (4.1)
#   sphinx_rtd_theme (unknown version)
#   sphinx.ext.autodoc.preserve_defaults (7.2.6)
#   sphinx.ext.autodoc.type_comment (7.2.6)
#   sphinx.ext.autodoc.typehints (7.2.6)
#   sphinx.ext.autodoc (7.2.6)
#   sphinx_github_changelog (1.3.0)
#   sphinxcontrib.httpdomain (unknown version)
#   sphinxcontrib.openapi (0.8.4)
#   notfound.extension (1.0.0)

# Traceback:
Traceback (most recent call last):
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\cmd\build.py", line 298, in build_main
    app.build(args.force_all, args.filenames)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\application.py", line 355, in build
    self.builder.build_update()
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\builders\__init__.py", line 293, in build_update
    self.build(to_build,
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\builders\__init__.py", line 313, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\builders\__init__.py", line 420, in read
    self._read_serial(docnames)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\builders\__init__.py", line 441, in _read_serial
    self.read_doc(docname)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\builders\__init__.py", line 498, in read_doc
    publisher.publish()
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\core.py", line 234, in publish
    self.document = self.reader.read(self.source, self.parser,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\io.py", line 105, in read
    self.parse()
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\readers\__init__.py", line 76, in parse
    self.parser.parse(self.input, document)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinx\parsers.py", line 81, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 169, in run
    results = StateMachineWS.run(self, input_lines, input_offset,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
                                  ^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2785, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
                   ^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
                                  ^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2785, in underline
    self.section(title, source, style, lineno - 1, messages)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 325, in section
    self.new_subsection(title, lineno, messages)
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 391, in new_subsection
    newabsoffset = self.nested_parse(
                   ^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 279, in nested_parse
    state_machine.run(block, input_offset, memo=self.memo,
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 195, in run
    results = StateMachineWS.run(self, input_lines, input_offset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
                                  ^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\statemachine.py", line 445, in check_line
    return method(match, context, next_state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2355, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2367, in explicit_construct
    return method(self, expmatch)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2104, in directive
    return self.run_directive(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\docutils\parsers\rst\states.py", line 2154, in run_directive
    result = directive_instance.run()
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinxcontrib\openapi\directive.py", line 55, in run
    spec = _get_spec(abspath, encoding)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\sphinxcontrib\openapi\directive.py", line 23, in _get_spec
    return yaml.safe_load(stream)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\__init__.py", line 125, in safe_load
    return load(stream, SafeLoader)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\__init__.py", line 81, in load
    return loader.get_single_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 51, in get_single_data
    return self.construct_document(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 60, in construct_document
    for dummy in generator:
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 143, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 100, in construct_object
    data = constructor(self, node)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Programmieren\ephios\venv\Lib\site-packages\yaml\constructor.py", line 427, in construct_undefined
    raise ConstructorError(None, None,
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/object/apply:django.utils.functional._lazy_proxy_unpickle'
  in "C:\Users\username\Programmieren\ephios\docs\api\ephios-open-api-schema.yml", line 318, column 22