You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
OutOfRange exception is not handled in execute call. #570
Run an insert query on db with a check constraint for values in a list.
Exception is thrown as : google.api_core.exceptions.OutOfRange: 400 Check constraint constraints_product.unicode_unit_list is violated for key ...
Code example
# Create table with constrain as shown:classProduct(models.Model):
price=models.IntegerField(null=True)
discounted_price=models.IntegerField(null=True)
unit=models.CharField(max_length=15, null=True)
classMeta:
required_db_features= {
"supports_table_check_constraints",
}
constraints= [
models.CheckConstraint(
check=models.Q(
models.Q(unit__isnull=True) |models.Q(unit__in=["μg/mL", "ng/mL"])
),
name="unicode_unit_list",
),
]
# Insert data in table which violates the constraint.Product.objects.create(price=10, discounted_price=7, unit="l")
Stack trace
return executor(sql, params, many, context)
File "/Users/viki/Documents/django3.2/django/db/backends/utils.py", line 92, in _execute
if params is None:
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_dbapi/cursor.py", line 239, in execute
_helpers.handle_insert(self.connection, sql, args or None)
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_dbapi/_helpers.py", line 97, in handle_insert
return connection.database.run_in_transaction(
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_v1/database.py", line 659, in run_in_transaction
return session.run_in_transaction(func, *args, **kw)
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_v1/session.py", line 358, in run_in_transaction
return_value = func(txn, *args, **kw)
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_dbapi/_helpers.py", line 62, in _execute_insert_heterogenous
transaction.execute_update(sql, params=params, param_types=param_types)
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_v1/transaction.py", line 297, in execute_update
response = api.execute_sql(
File "/Users/viki/Documents/python-spanner/google/cloud/spanner_v1/services/spanner/client.py", line 829, in execute_sql
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
File "/Users/viki/.virtualenvs/django3.2/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
return wrapped_func(*args, **kwargs)
File "/Users/viki/.virtualenvs/django3.2/lib/python3.9/site-packages/google/api_core/retry.py", line 285, in retry_wrapped_func
return retry_target(
File "/Users/viki/.virtualenvs/django3.2/lib/python3.9/site-packages/google/api_core/retry.py", line 188, in retry_target
return target()
File "/Users/viki/.virtualenvs/django3.2/lib/python3.9/site-packages/google/api_core/timeout.py", line 102, in func_with_timeout
return func(*args, **kwargs)
File "/Users/viki/.virtualenvs/django3.2/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 69, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.OutOfRange: 400 Check constraint `constraints_product`.`unicode_unit_list` is violated for key {Int64(3748556580426276960)}
Activity