Fix deep_update for Python 3.10 (#8394)

This is only used by the Elasticsearch backend, so we were missing test runs for it over all Python versions.

Thanks to @przemub for reporting and the initial fix.
pull/8549/head
Matt Westcott 2022-04-20 14:00:38 +01:00
rodzic 7b0413ae29
commit 9cbd717313
3 zmienionych plików z 39 dodań i 2 usunięć

Wyświetl plik

@ -591,6 +591,7 @@ Contributors
* Kyle J. Roux
* Vaibhav Shukla
* Rishank Kanaparti
* Przemysław Buczkowski
Translators
===========

Wyświetl plik

@ -18,6 +18,7 @@ from wagtail.coreutils import (
string_to_ascii,
)
from wagtail.models import Page, Site
from wagtail.utils.utils import deep_update
class TestCamelCaseToUnderscore(TestCase):
@ -405,3 +406,38 @@ class TestGetDummyRequest(TestCase):
request = get_dummy_request(site=site)
self.assertEqual(request.get_host(), "other.example.com:8888")
class TestDeepUpdate(TestCase):
def test_deep_update(self):
val = {
"captain": "picard",
"beverage": {
"type": "coffee",
"temperature": "hot",
},
}
deep_update(
val,
{
"beverage": {
"type": "tea",
"variant": "earl grey",
},
"starship": "enterprise",
},
)
self.assertEqual(
val,
{
"captain": "picard",
"beverage": {
"type": "tea",
"variant": "earl grey",
"temperature": "hot",
},
"starship": "enterprise",
},
)

Wyświetl plik

@ -1,4 +1,4 @@
import collections
from collections.abc import Mapping
def deep_update(source, overrides):
@ -7,7 +7,7 @@ def deep_update(source, overrides):
Modify ``source`` in place.
"""
for key, value in overrides.items():
if isinstance(value, collections.Mapping) and value:
if isinstance(value, Mapping) and value:
returned = deep_update(source.get(key, {}), value)
source[key] = returned
else: