Merge pull request #767 from tcely/patch-3

Prevent unintended changes to the cached dictionary
This commit is contained in:
meeb 2025-02-24 22:42:53 +11:00 committed by GitHub
commit e45fce54bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,10 +2,11 @@ import os
import uuid import uuid
import json import json
import re import re
from xml.etree import ElementTree
from collections import OrderedDict from collections import OrderedDict
from copy import deepcopy
from datetime import datetime, timedelta, timezone as tz from datetime import datetime, timedelta, timezone as tz
from pathlib import Path from pathlib import Path
from xml.etree import ElementTree
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.core.exceptions import SuspiciousOperation from django.core.exceptions import SuspiciousOperation
@ -1058,7 +1059,7 @@ class Media(models.Model):
if not data: if not data:
cached = getattr(self, '_cached_metadata_dict', None) cached = getattr(self, '_cached_metadata_dict', None)
if cached: if cached:
data = cached return deepcopy(cached)
else: else:
data = json.loads(self.metadata or "{}") data = json.loads(self.metadata or "{}")
if not isinstance(data, dict): if not isinstance(data, dict):