manage.py Wagtail 2.15 升级后出错

manage.py error after Wagtail 2.15 upgrade

从 2.14.2 升级到 Wagtail 2.15(或 2.15.1)后,我的生产网站使用 postgres 和数据库搜索中断,运行 和 manage.py 的命令给出错误,尽管我添加了设置所需的 WAGTAILSEARCH_BACKENDS

我有两个具有不同设置的 Web 应用程序 运行来自同一个 Wagtail 版本。其中一个应用程序 (putkeep) 有一个搜索栏,另一个 (secretgifter) 没有。将 Wagtail 从 2.14.2 升级到 2.15 后,putkeep 给出了 404 错误,但 secretgifter 没有。如果我使用 pip 切换回 2.14.2,则 404 错误消失并且网站加载(尽管搜索结果给出 500 错误)。

如果我 运行 makemigrations(或任何其他使用 manage.py 的命令)用于 secretgifter,它工作正常。对于 putkeep(通过搜索),它给出了以下错误:

  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/apps.py", line 21, in ready
    set_weights()
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 44, in set_weights
    BOOSTS_WEIGHTS.extend(determine_boosts_weights())
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 32, in determine_boosts_weights
    boosts = get_boosts()
  File "/home/th-putkeep.net/putkeep/lib/python3.8/site-packages/wagtail/search/backends/database/postgres/weights.py", line 26, in get_boosts
    boosts.add(boost)
TypeError: unhashable type: 'list'

根据文档,我已将其添加到我的设置中:

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail.search.backends.database',
    }
}

非常感谢收到任何建议。

我在我的 models.py 中发现了一些代码,这些代码对我的站点 运行 Wagtail 2.14.2 及以下版本没有造成任何错误。注释掉后,解决了升级到 Wagtail 2.15 及以上版本导致的错误。我将它发布在这里作为我的问题的答案,因为其他一切似乎都可以工作(包括搜索)而无需任何进一步修改,即使我目前不确定它为什么会导致错误或者我是否需要它:

    search_fields = Page.search_fields + [  # Inherit search_fields from Page
        index.SearchField('content'),
        index.SearchField('tags', [
            index.SearchField('name', partial_match=True, boost=10),
        ]),
    ]

我认为问题在于您尝试搜索标签名称的配置:

index.SearchField('tags', [
    index.SearchField('name', partial_match=True, boost=10),
]),

默认数据库搜索似乎不提供以这种方式搜索相关对象的选项(请参阅 https://docs.wagtail.io/en/stable/topics/search/indexing.html#indexing-callables-and-other-attributes 下的注释)。您可以删除这些行,或者暂时返回 wagtail/contrib 中的 postgres_search 后端。