Skip to content

cassandra.cql: Use static dataclasses instead of generating namedtuples on the fly.

Before this commit, python-cassandra used the default row factory, which creates anonymous named tuple on each query, which makes it impossible to type CqlRunner properly.

This commit replaces the row factory with dict_factory, which creates only dicts, and converts them to well-defined dataclasses. Additionally, this stop leaking python-cassandra internals to cassandra.storage.

This also has some great side-effects:

  • methods of CqlRunner are now consistent with each other (eg. _add_one methods used to be a mix of objects, dictionaries, and taking each value as argument)
  • it will allow me to deduplicate more codes in further commits (I already deduplicated insertions methods to use self._add_one, as it was meant on the initial write of this class)
  • CqlRunner no longer needs to define lists with column names, they are automatically detected from the dataclasses

Migrated from D3756 (view on Phabricator)

Merge request reports