Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/sentry/api/endpoints/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ def get(self, request, organization):
:auth: required
"""
endpoint = options.get("system.upload-url-prefix")
# We fallback to default system url if config is not set
if len(endpoint) == 0:
endpoint = options.get("system.url-prefix")
relative_url = reverse("sentry-api-0-chunk-upload", args=[organization.slug])

url = reverse("sentry-api-0-chunk-upload", args=[organization.slug])
endpoint = urljoin(endpoint.rstrip("/") + "/", url.lstrip("/"))
if len(endpoint) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC system.upload-url-prefix is registered with None as default value:

register("system.upload-url-prefix", flags=FLAG_PRIORITIZE_DISK)

This means this len() will raise a TypeError if the option is not set. I think the pythonic way to write this is if not endpoint:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been written like this for 4 years now, so I didn't want to change this, as I don't know the history of this code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, that if condition was already there. hum. i think this is weird and we somehow got lucky so far. but i guess we have some confidence this won't blow up in prod so i don't mind 😄

# If config is not set, we return relative, versionless endpoint (with `/api/0` stripped)
prefix = "/api/0"
url = relative_url.replace(prefix, "/")
else:
# Otherwise, we want a relative, versioned endpoint, with user-configured prefix
url = urljoin(endpoint.rstrip("/") + "/", relative_url.lstrip("/"))

return Response(
{
"url": endpoint,
"url": url,
"chunkSize": settings.SENTRY_CHUNK_UPLOAD_BLOB_SIZE,
"chunksPerRequest": MAX_CHUNKS_PER_REQUEST,
"maxFileSize": get_max_file_size(organization),
Expand Down
7 changes: 1 addition & 6 deletions tests/sentry/api/endpoints/test_chunk_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,14 @@ def test_chunk_parameters(self):
self.url, HTTP_AUTHORIZATION=f"Bearer {self.token.token}", format="json"
)

endpoint = options.get("system.upload-url-prefix")
# We fallback to default system url if config is not set
if len(endpoint) == 0:
endpoint = options.get("system.url-prefix")

assert response.status_code == 200, response.content
assert response.data["chunkSize"] == settings.SENTRY_CHUNK_UPLOAD_BLOB_SIZE
assert response.data["chunksPerRequest"] == MAX_CHUNKS_PER_REQUEST
assert response.data["maxRequestSize"] == MAX_REQUEST_SIZE
assert response.data["maxFileSize"] == options.get("system.maximum-file-size")
assert response.data["concurrency"] == MAX_CONCURRENCY
assert response.data["hashAlgorithm"] == HASH_ALGORITHM
assert response.data["url"] == options.get("system.url-prefix") + self.url
assert response.data["url"] == self.url.replace("/api/0", "/")

options.set("system.upload-url-prefix", "test")
response = self.client.get(
Expand Down