Skip to content

Commit

Permalink
Prevent possible incorrect results when proxies=False fix #61, #71
Browse files Browse the repository at this point in the history
Don't track the id() of objects other than our JsonRefs. We can't guarantee that memory won't be released and reused for the other objects.
  • Loading branch information
gazpachoking committed Jan 28, 2025
1 parent 2d3bf8b commit e827f23
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions jsonref/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from urllib import parse as urlparse
from urllib.parse import unquote
from urllib.request import urlopen

from . import proxytypes # noqa: F401
from .proxytypes import LazyProxy

Expand Down Expand Up @@ -261,13 +262,13 @@ def jsonloader(uri, **kwargs):
def _walk_refs(obj, func, replace=False, _processed=None):
# Keep track of already processed items to prevent recursion
_processed = _processed or {}
oid = id(obj)
if oid in _processed:
return _processed[oid]
if type(obj) is JsonRef:
oid = id(obj)
if oid in _processed:
return _processed[oid]
r = func(obj)
obj = r if replace else obj
_processed[oid] = obj
_processed[oid] = obj
if isinstance(obj, Mapping):
for k, v in obj.items():
r = _walk_refs(v, func, replace=replace, _processed=_processed)
Expand Down

0 comments on commit e827f23

Please sign in to comment.