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

Method save

cassandra/cqlengine/query.py:1465–1506  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

1463 self._delete_null_columns(delete_conditionals)
1464
1465 def save(self):
1466 """
1467 Creates / updates a row.
1468 This is a blind insert call.
1469 All validation and cleaning needs to happen
1470 prior to calling this.
1471 """
1472 if self.instance is None:
1473 raise CQLEngineException("DML Query instance attribute is None")
1474 assert type(self.instance) == self.model
1475
1476 nulled_fields = set()
1477 if self.instance._has_counter or self.instance._can_update():
1478 if self.instance._has_counter:
1479 warn("'create' and 'save' actions on Counters are deprecated. It will be disallowed in 4.0. "
1480 "Use the 'update' mechanism instead.", DeprecationWarning)
1481 return self.update()
1482 else:
1483 insert = InsertStatement(self.column_family_name, ttl=self._ttl, timestamp=self._timestamp, if_not_exists=self._if_not_exists)
1484 static_save_only = False if len(self.instance._clustering_keys) == 0 else True
1485 for name, col in self.instance._clustering_keys.items():
1486 static_save_only = static_save_only and col._val_is_null(getattr(self.instance, name, None))
1487 for name, col in self.instance._columns.items():
1488 if static_save_only and not col.static and not col.partition_key:
1489 continue
1490 val = getattr(self.instance, name, None)
1491 if col._val_is_null(val):
1492 if self.instance._values[name].changed:
1493 nulled_fields.add(col.db_field_name)
1494 continue
1495 if col.has_default and not self.instance._values[name].changed:
1496 # Ensure default columns included in a save() are marked as explicit, to get them *persisted* properly
1497 self.instance._values[name].explicit = True
1498 insert.add_assignment(col, getattr(self.instance, name, None))
1499
1500 # skip query execution if it's empty
1501 # caused by pointless update queries
1502 if not insert.is_empty:
1503 self._execute(insert)
1504 # delete any nulled columns
1505 if not static_save_only:
1506 self._delete_null_columns()
1507
1508 def delete(self):
1509 """ Deletes one instance """

Callers 1

createMethod · 0.45

Calls 11

updateMethod · 0.95
_executeMethod · 0.95
_delete_null_columnsMethod · 0.95
CQLEngineExceptionClass · 0.90
InsertStatementClass · 0.90
setFunction · 0.85
_can_updateMethod · 0.80
add_assignmentMethod · 0.80
itemsMethod · 0.45
_val_is_nullMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected