Skip to content

Commit

Permalink
return early
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed May 10, 2024
1 parent 66eff13 commit 2648759
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions sentry_sdk/integrations/django/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,26 @@ def _patch_cache(cache, address=None, port=None):

def _get_address_port(settings):
# type: (dict[str, Any]) -> tuple[Optional[str], Optional[int]]
address, port = None, None
location = settings.get("LOCATION")

# TODO: location can also be an array of locations
# see: https://docs.djangoproject.com/en/5.0/topics/cache/#redis
# GitHub issue: https://github.com/getsentry/sentry-python/issues/3062
if isinstance(location, str):
if "://" in location:
parsed_url = urlparse(location)
# remove the username and password from URL to not leak sensitive data.
address = "{}://{}{}".format(
parsed_url.scheme or "",
parsed_url.hostname or "",
parsed_url.path or "",
)
port = parsed_url.port
else:
address = location
port = None
if not isinstance(location, str):
return None, None

if "://" in location:
parsed_url = urlparse(location)
# remove the username and password from URL to not leak sensitive data.
address = "{}://{}{}".format(
parsed_url.scheme or "",
parsed_url.hostname or "",
parsed_url.path or "",
)
port = parsed_url.port
else:
address = location
port = None

return address, int(port) if port is not None else None

Expand Down

0 comments on commit 2648759

Please sign in to comment.