pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

invalid subdocument field when using ajax refs on an embedded document if the field is from an inherited class #1778

Open gordol opened 5 years ago

gordol commented 5 years ago
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/model/base.py", line 804, in __init__
    self._refresh_cache()
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/view.py", line 276, in _refresh_cache
    super(ModelView, self)._refresh_cache()
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/model/base.py", line 896, in _refresh_cache
    self._refresh_forms_cache()
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/model/base.py", line 816, in _refresh_forms_cache
    self._form_ajax_refs = self._process_ajax_references()
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/view.py", line 288, in _process_ajax_references
    return process_ajax_references(references, self)
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/ajax.py", line 140, in process_ajax_references
    handle_subdoc(view.model, view, '')
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/ajax.py", line 138, in handle_subdoc
    handle_field(field, doc, make_name(base, name))
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/ajax.py", line 104, in handle_field
    handle_field(field.field, child_doc, base)
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/ajax.py", line 125, in handle_field
    handle_subdoc(field.document_type_obj, subdoc, base)
  File "/srv/--redacted--/.virtualenvs/--redacted---pypy/site-packages/flask_admin/contrib/mongoengine/ajax.py", line 136, in handle_subdoc
    raise ValueError('Invalid subdocument field %s.%s' % (model, name))
ValueError: Invalid subdocument field <class 'backend.models.ModelName'>.inherited_field_from_parent_class

not sure yet if this is a bug with mongoengine specifically, or an overall pattern flaw with the way inherited fields are handled.

gordol commented 5 years ago

Basically I just have some naked parent classes with some fields in them, and then in inherit those classes into my EmbeddedDocument class. The embedded document class can then no longer use ajax refs on any of those inherited model fields.