ixc / wagtail-instance-selector

A widget for Wagtail's admin that allows you to create and select related items
MIT License
54 stars 17 forks source link

Error: Field 'id' expected a number #15

Closed tbrlpld closed 3 years ago

tbrlpld commented 3 years ago

Hi, I am currently trying to get the instance selector working on a new project.

django 3.1.11     
wagtail 2.12.4   
wagtail-instance-selector 2.1.0
...

I have this model:

class Resource(models.Model):
    title = models.CharField(max_length=250)

and this page type:

class InformationPage(BasePage):
    ...

    resources = models.ForeignKey(Resource, on_delete=models.SET_NULL, null=True, blank=True)

    content_panels = BasePage.content_panels + [
        ...
        inst_handlers.InstanceSelectorPanel("resources"),
    ]

When I now try to create a new instance of that page type, I get the following error:

Template error:
In template /home/rittc/.local/lib/python3.8/site-packages/wagtail/admin/templates/wagtailadmin/shared/field.html, error at line 7
   Field 'id' expected a number but got {'pk': None, 'display_markup': '<div class="instance-selector-widget__display instance-selector-widget__display--no-image">\n    <div class="instance-selector-widget__display__image-wrap">\n        <a\n            href="None"\n            class="instance-selector-widget__display__edit-link instance-selector-widget__display__edit-link--image js-instance-selector-widget-display-edit-link"\n            target="_blank"\n        >\n            <img\n                \n                class="instance-selector-widget__display__image"\n                \n                    style="max-width: 165px; max-height: 165px; "\n                \n            >\n        </a>\n    </div>\n    <div class="instance-selector-widget__display__title-wrap">\n        <a\n            href="None"\n            class="instance-selector-widget__display__edit-link instance-selector-widget__display__edit-link--title js-instance-selector-widget-display-edit-link"\n            target="_blank"\n        >\n            <span class="instance-selector-widget__display__title">None</span>\n        </a>\n    </div>\n</div>\n', 'edit_url': None}.
   1 : {% load wagtailadmin_tags %}
   2 : <div class="field {{ field|fieldtype }} {{ field|widgettype }} {{ field_classes }}">
   3 :     {% if show_label|default_if_none:True %}{{ field.label_tag }}{% endif %}
   4 :     <div class="field-content">
   5 :         <div class="input {{ input_classes }} ">
   6 :             {% block form_field %}
   7 :                  {{ field|render_with_errors }} 
   8 :             {% endblock %}
   9 :             
   10 :             {# This span only used on rare occasions by certain types of input #}
   11 :             <span></span>
   12 :         </div>
   13 :         {% if show_help_text|default_if_none:True and field.help_text %}
   14 :             <p class="help">{{ field.help_text }}</p>
   15 :         {% endif %}
   16 : 
   17 :         {% if field|has_unrendered_errors %}
...

The page model works fine when I comment the inst_handlers.InstanceSelectorPanel("resources"), line.

Migrations have been created and run.

Any pointers on what might be wrong here? I suspect some version issue here since the setup is minimal.

markfinger commented 3 years ago

Strange, haven't seen that one before.

We recently published 2.1.0, can you try with 2.0.0 and see if that makes a difference?

tbrlpld commented 3 years ago

It works with 2.0.1 👍

I guess the fixes for Wagtail 2.13 broke something with the older versions (I am on 2.12.4).

gasman commented 3 years ago

Sorry, I think I screwed up with the version check in my 2.13 compatibility fixes... same thing as here I suspect. https://github.com/wagtail/wagtail-generic-chooser/pull/32

markfinger commented 3 years ago

@tbrlpld, thanks for the report. I've published 2.1.1 with @gasman's fix.