Skip to content

Commit

Permalink
Fix crashing syncing thread when logging big integers (#1336)
Browse files Browse the repository at this point in the history
  • Loading branch information
aniezurawski authored May 8, 2023
1 parent 5af917b commit 6cf541a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
### Features
- Series objects accept `timestamps` and `steps` in their constructors ([#1318](https://github.com/neptune-ai/neptune-client/pull/1318))

### Fixes
- Print warning instead of crashing syncing thread when logging big integers ([#1336](https://github.com/neptune-ai/neptune-client/pull/1336))

## neptune 1.1.1

### Fixes
Expand Down
17 changes: 17 additions & 0 deletions src/neptune/attributes/atoms/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
from neptune.attributes.atoms.copiable_atom import CopiableAtom
from neptune.internal.container_type import ContainerType
from neptune.internal.operation import AssignInt
from neptune.internal.utils.logger import logger
from neptune.types.atoms.integer import Integer as IntegerVal

if typing.TYPE_CHECKING:
from neptune.internal.backends.neptune_backend import NeptuneBackend


class Integer(CopiableAtom):

MAX_32_BIT_INT = 2147483647
MIN_32_BIT_INT = -2147483648

@staticmethod
def create_assignment_operation(path, value: int):
return AssignInt(path, value)
Expand All @@ -45,5 +50,17 @@ def assign(self, value: typing.Union[IntegerVal, float, int], *, wait: bool = Fa
if not isinstance(value, IntegerVal):
value = IntegerVal(value)

if value.value < Integer.MIN_32_BIT_INT or value.value > Integer.MAX_32_BIT_INT:
logger.warning(
"WARNING: The value you're trying to log is outside the range of 32-bit integers "
"(%s to %s) and will be skipped. "
"We'll support 64-bit integers in the future. "
'For now, try logging the value as a float instead: run["field"] = float(%s)',
Integer.MIN_32_BIT_INT,
Integer.MAX_32_BIT_INT,
value.value,
)
return

with self._container.lock():
self._enqueue_operation(self.create_assignment_operation(self._path, value.value), wait=wait)

0 comments on commit 6cf541a

Please sign in to comment.