MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / update

Method update

cassandra/cqlengine/models.py:748–799  ·  view source on GitHub ↗

Performs an update on the model instance. You can pass in values to set on the model for updating, or you can call without values to execute an update against any modified fields. If no fields on the model have been modified since loading, no query will be performed.

(self, **values)

Source from the content-addressed store, hash-verified

746 return self
747
748 def update(self, **values):
749 """
750 Performs an update on the model instance. You can pass in values to set on the model
751 for updating, or you can call without values to execute an update against any modified
752 fields. If no fields on the model have been modified since loading, no query will be
753 performed. Model validation is performed normally. Setting a value to `None` is
754 equivalent to running a CQL `DELETE` on that column.
755
756 It is possible to do a blind update, that is, to update a field without having first selected the object out of the database.
757 See :ref:`Blind Updates <blind_updates>`
758 """
759 for column_id, v in values.items():
760 col = self._columns.get(column_id)
761
762 # check for nonexistant columns
763 if col is None:
764 raise ValidationError(
765 "{0}.{1} has no column named: {2}".format(
766 self.__module__, self.__class__.__name__, column_id))
767
768 # check for primary key update attempts
769 if col.is_primary_key:
770 current_value = getattr(self, column_id)
771 if v != current_value:
772 raise ValidationError(
773 "Cannot apply update to primary key '{0}' for {1}.{2}".format(
774 column_id, self.__module__, self.__class__.__name__))
775
776 setattr(self, column_id, v)
777
778 # handle polymorphic models
779 if self._is_polymorphic:
780 if self._is_polymorphic_base:
781 raise PolymorphicModelException('cannot update polymorphic base model')
782 else:
783 setattr(self, self._discriminator_column_name, self.__discriminator_value__)
784
785 self.validate()
786 self.__dmlquery__(self.__class__, self,
787 batch=self._batch,
788 ttl=self._ttl,
789 timestamp=self._timestamp,
790 consistency=self.__consistency__,
791 conditional=self._conditional,
792 timeout=self._timeout,
793 if_exists=self._if_exists).update()
794
795 self._set_persisted()
796
797 self._timestamp = None
798
799 return self
800
801 def delete(self):
802 """

Callers

nothing calls this directly

Calls 6

validateMethod · 0.95
_set_persistedMethod · 0.95
ValidationErrorClass · 0.90
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected