Skip to content

Commit 0af5512

Browse files
Set FILESIZE_LIMIT_MB via environment variables (#1466)
* add TSC_FILESIZE_LIMIT_MB environment variable * add hard limit for filesize limit at 64MB * fix formatting --------- Co-authored-by: Jac <[email protected]>
1 parent 9495fe8 commit 0af5512

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

tableauserverclient/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
DELAY_SLEEP_SECONDS = 0.1
88

9-
# The maximum size of a file that can be published in a single request is 64MB
10-
FILESIZE_LIMIT_MB = 64
11-
129

1310
class Config:
11+
# The maximum size of a file that can be published in a single request is 64MB
12+
@property
13+
def FILESIZE_LIMIT_MB(self):
14+
return min(int(os.getenv("TSC_FILESIZE_LIMIT_MB", 64)), 64)
15+
1416
# For when a datasource is over 64MB, break it into 5MB(standard chunk size) chunks
1517
@property
1618
def CHUNK_SIZE_MB(self):

tableauserverclient/server/endpoint/custom_views_endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from typing import Optional, Union
66

7-
from tableauserverclient.config import BYTES_PER_MB, FILESIZE_LIMIT_MB
7+
from tableauserverclient.config import BYTES_PER_MB, config
88
from tableauserverclient.filesys_helpers import get_file_object_size
99
from tableauserverclient.server.endpoint.endpoint import QuerysetEndpoint, api
1010
from tableauserverclient.server.endpoint.exceptions import MissingRequiredFieldError
@@ -144,7 +144,7 @@ def publish(self, view_item: CustomViewItem, file: PathOrFileR) -> Optional[Cust
144144
else:
145145
raise ValueError("File path or file object required for publishing custom view.")
146146

147-
if size >= FILESIZE_LIMIT_MB * BYTES_PER_MB:
147+
if size >= config.FILESIZE_LIMIT_MB * BYTES_PER_MB:
148148
upload_session_id = self.parent_srv.fileuploads.upload(file)
149149
url = f"{url}?uploadSessionId={upload_session_id}"
150150
xml_request, content_type = RequestFactory.CustomView.publish_req_chunked(view_item)

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from tableauserverclient.server.endpoint.permissions_endpoint import _PermissionsEndpoint
2424
from tableauserverclient.server.endpoint.resource_tagger import TaggingMixin
2525

26-
from tableauserverclient.config import ALLOWED_FILE_EXTENSIONS, FILESIZE_LIMIT_MB, BYTES_PER_MB, config
26+
from tableauserverclient.config import ALLOWED_FILE_EXTENSIONS, BYTES_PER_MB, config
2727
from tableauserverclient.filesys_helpers import (
2828
make_download_path,
2929
get_file_type,
@@ -268,10 +268,10 @@ def publish(
268268
url += "&{}=true".format("asJob")
269269

270270
# Determine if chunking is required (64MB is the limit for single upload method)
271-
if file_size >= FILESIZE_LIMIT_MB * BYTES_PER_MB:
271+
if file_size >= config.FILESIZE_LIMIT_MB * BYTES_PER_MB:
272272
logger.info(
273273
"Publishing {} to server with chunking method (datasource over {}MB, chunk size {}MB)".format(
274-
filename, FILESIZE_LIMIT_MB, config.CHUNK_SIZE_MB
274+
filename, config.FILESIZE_LIMIT_MB, config.CHUNK_SIZE_MB
275275
)
276276
)
277277
upload_session_id = self.parent_srv.fileuploads.upload(file)

0 commit comments

Comments
 (0)