From 3d1e776e8eb25cb3a8a6f2b4073983ced0d4d4ac Mon Sep 17 00:00:00 2001 From: Jakub Kuszneruk Date: Tue, 23 Nov 2021 14:14:49 +0100 Subject: [PATCH] Limit length of `custom_run_id` (#748) * Limit length of `custom_run_id` * Limit length of `custom_run_id` * re-black Co-authored-by: Piotr Kasprzyk --- neptune/new/internal/init_impl.py | 6 ++---- neptune/new/internal/utils/limits.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/neptune/new/internal/init_impl.py b/neptune/new/internal/init_impl.py index 8f3cc59ab..2c61d82eb 100644 --- a/neptune/new/internal/init_impl.py +++ b/neptune/new/internal/init_impl.py @@ -49,6 +49,7 @@ ) from neptune.new.internal.utils import verify_collection_type, verify_type from neptune.new.internal.utils.git import discover_git_repo_location, get_git_info +from neptune.new.internal.utils.limits import custom_run_id_exceeds_length from neptune.new.internal.utils.ping_background_job import PingBackgroundJob from neptune.new.internal.utils.runningmode import in_interactive, in_notebook from neptune.new.internal.utils.source_code import upload_source_code @@ -249,10 +250,7 @@ def init( if mode == Mode.READ_ONLY: raise NeedExistingRunForReadOnlyMode() git_ref = get_git_info(discover_git_repo_location()) - if custom_run_id and len(custom_run_id) > 32: - _logger.warning( - "Given custom_run_id exceeds 32 characters and it will be ignored." - ) + if custom_run_id_exceeds_length(custom_run_id): custom_run_id = None notebook_id, checkpoint_id = _create_notebook_checkpoint(backend) diff --git a/neptune/new/internal/utils/limits.py b/neptune/new/internal/utils/limits.py index 37865c404..f15beabb4 100644 --- a/neptune/new/internal/utils/limits.py +++ b/neptune/new/internal/utils/limits.py @@ -18,6 +18,7 @@ _logger = logging.getLogger(__name__) +_CUSTOM_RUN_ID_LENGTH = 36 _IMAGE_SIZE_LIMIT_MB = 15 _IN_MEMORY_SIZE_LIMIT_MB = 32 _STREAM_SIZE_LIMIT_MB = 32 @@ -27,6 +28,16 @@ STREAM_SIZE_LIMIT_BYTES = _STREAM_SIZE_LIMIT_MB * BYTES_IN_MB +def custom_run_id_exceeds_length(custom_run_id): + if custom_run_id and len(custom_run_id) > _CUSTOM_RUN_ID_LENGTH: + _logger.warning( + "Given custom_run_id exceeds %s" " characters and it will be ignored.", + _CUSTOM_RUN_ID_LENGTH, + ) + return True + return False + + def image_size_exceeds_limit(content_size): if content_size > _IMAGE_SIZE_LIMIT_MB * BYTES_IN_MB: _logger.warning(