MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / update

Method update

cassandra/cqlengine/query.py:1414–1463  ·  view source on GitHub ↗

updates a row. This is a blind update call. All validation and cleaning needs to happen prior to calling this.

(self)

Source from the content-addressed store, hash-verified

1412 self._execute(ds)
1413
1414 def update(self):
1415 """
1416 updates a row.
1417 This is a blind update call.
1418 All validation and cleaning needs to happen
1419 prior to calling this.
1420 """
1421 if self.instance is None:
1422 raise CQLEngineException("DML Query instance attribute is None")
1423 assert type(self.instance) == self.model
1424 null_clustering_key = False if len(self.instance._clustering_keys) == 0 else True
1425 static_changed_only = True
1426 statement = UpdateStatement(self.column_family_name, ttl=self._ttl, timestamp=self._timestamp,
1427 conditionals=self._conditional, if_exists=self._if_exists)
1428 for name, col in self.instance._clustering_keys.items():
1429 null_clustering_key = null_clustering_key and col._val_is_null(getattr(self.instance, name, None))
1430
1431 updated_columns = set()
1432 # get defined fields and their column names
1433 for name, col in self.model._columns.items():
1434 # if clustering key is null, don't include non-static columns
1435 if null_clustering_key and not col.static and not col.partition_key:
1436 continue
1437 if not col.is_primary_key:
1438 val = getattr(self.instance, name, None)
1439 val_mgr = self.instance._values[name]
1440
1441 if val is None:
1442 continue
1443
1444 if not val_mgr.changed and not isinstance(col, columns.Counter):
1445 continue
1446
1447 static_changed_only = static_changed_only and col.static
1448 statement.add_update(col, val, previous=val_mgr.previous_value)
1449 updated_columns.add(col.db_field_name)
1450
1451 if statement.assignments:
1452 for name, col in self.model._primary_keys.items():
1453 # only include clustering key if clustering key is not null, and non-static columns are changed to avoid cql error
1454 if (null_clustering_key or static_changed_only) and (not col.partition_key):
1455 continue
1456 statement.add_where(col, EqualsOperator(), getattr(self.instance, name))
1457 self._execute(statement)
1458
1459 if not null_clustering_key:
1460 # remove conditions on fields that have been updated
1461 delete_conditionals = [condition for condition in self._conditional
1462 if condition.field not in updated_columns] if self._conditional else None
1463 self._delete_null_columns(delete_conditionals)
1464
1465 def save(self):
1466 """

Callers 6

saveMethod · 0.95
executeMethod · 0.45
_only_or_deferMethod · 0.45
encryptMethod · 0.45
decryptMethod · 0.45

Calls 11

add_updateMethod · 0.95
_executeMethod · 0.95
_delete_null_columnsMethod · 0.95
CQLEngineExceptionClass · 0.90
UpdateStatementClass · 0.90
EqualsOperatorClass · 0.90
setFunction · 0.85
add_whereMethod · 0.80
itemsMethod · 0.45
_val_is_nullMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected