Skip to content

Commit dbd05f6

Browse files
authored
Truncate description in SQS message by bytes (#17587)
1 parent c6595a6 commit dbd05f6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

warehouse/forklift/legacy.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# under this when enqueuing a job to store BigQuery metadata, we truncate the
9494
# Description field to 40K bytes, which captures up to the 95th percentile of
9595
# existing descriptions.
96-
MAX_DESCRIPTION_LENGTH_TO_BIGQUERY = 40000
96+
MAX_DESCRIPTION_LENGTH_TO_BIGQUERY_IN_BYTES = 40000
9797

9898
# Wheel platform checking
9999

@@ -1611,7 +1611,10 @@ def file_upload(request):
16111611
"version": str(meta.version),
16121612
"summary": meta.summary,
16131613
"description": (
1614-
meta.description[:MAX_DESCRIPTION_LENGTH_TO_BIGQUERY]
1614+
# Truncate the description by bytes and not characters if it is too long
1615+
meta.description.encode()[
1616+
:MAX_DESCRIPTION_LENGTH_TO_BIGQUERY_IN_BYTES
1617+
].decode("utf-8", "ignore")
16151618
if meta.description is not None
16161619
else None
16171620
),

0 commit comments

Comments
 (0)