Skip to content

Improve link_row prepare_value_for_db_in_bulk handling of >32-bit integers #4738

@picklepete

Description

@picklepete

Describe the problem

Relates to Sentry issue 7258876168.

If a link_row field is PATCHed with an ID that overflows a 32-bit integer, the backend fails hard.

Steps to reproduce

  1. Add a link_row field to your table
  2. PATCH /api/database/rows/table/{tableId}/{rowId}/?user_field_names=true with data {"yourLinkRowField": [922469000000096100]

Actual result

The backend will fail hard:

  File "/baserow/venv/lib/python3.11/site-packages/django/db/models/query.py", line 825, in bulk_create
    returned_columns = self._batched_insert(
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/baserow/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1901, in _batched_insert
    self._insert(
  File "/baserow/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1873, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/baserow/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1882, in execute_sql
    cursor.execute(sql, params)
  File "/baserow/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/baserow/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/baserow/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/baserow/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/baserow/venv/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/baserow/venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.DataError: integer out of range

Expected result

We already have string/name validation, we could do with row ID validation, because:

  1. Per this issue, a >32bit integer will overflow the column type
  2. If you send a smaller integer that you know doesn't map to a real row ID, we seem to just skip it (try and send [999] or something).

Environment

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain::database 🗄️Key expertise in database is required, though the issue may also involve domain::core.type::bug 🐛Issues that report undesirable or incorrect behavior.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions