From 7ac62c7d9644c30371587b3e4869b296a8f0faa3 Mon Sep 17 00:00:00 2001 From: Javier Alperte Date: Fri, 30 Aug 2019 13:15:48 +0200 Subject: [PATCH 1/5] Set the custom version in the setup and mkdocs files. --- django_cassandra_engine/__init__.py | 2 +- mkdocs.yml | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django_cassandra_engine/__init__.py b/django_cassandra_engine/__init__.py index d1ad985..8c38fd8 100644 --- a/django_cassandra_engine/__init__.py +++ b/django_cassandra_engine/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Do not forget to change version number in mkdocs.yml also! -__version__ = (1, 5, 4) +#__version__ = (1, 5, 4) __author__ = "Rafał Furmański" __contact__ = "r.furmanski@gmail.com" __homepage__ = "http://github.com/r4fek/django-cassandra-engine" diff --git a/mkdocs.yml b/mkdocs.yml index d4afffc..b712695 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,7 +12,7 @@ repo_url: https://github.com/r4fek/django-cassandra-engine # Options extra: - version: 1.5.4 + version: 1.5.4-bgds-1 logo: images/dj_cassandra.png author: github: r4fek diff --git a/setup.py b/setup.py index b738249..7d05926 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='django-cassandra-engine', - version='.'.join(map(str, meta.__version__)), + version='1.5.4-bgds-1', author=meta.__author__, author_email=meta.__contact__, url=meta.__homepage__, From 7a019b2065acf6a2ccbb13c623a7565c396547de Mon Sep 17 00:00:00 2001 From: Javier Alperte Date: Tue, 3 Sep 2019 13:55:23 +0200 Subject: [PATCH 2/5] The creation py was using the cassandra imports instead of DSE when we use DSE. We changed the import to use the one in compat.py instead. --- django_cassandra_engine/base/creation.py | 5 ++--- django_cassandra_engine/compat.py | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django_cassandra_engine/base/creation.py b/django_cassandra_engine/base/creation.py index f0249d9..9f79a3e 100644 --- a/django_cassandra_engine/base/creation.py +++ b/django_cassandra_engine/base/creation.py @@ -1,8 +1,7 @@ import django -from cassandra.cqlengine.connection import set_default_connection - from django_cassandra_engine.utils import get_default_cassandra_connection -from ..compat import create_keyspace_simple, drop_keyspace +from ..compat import create_keyspace_simple, drop_keyspace, \ + set_default_connection if django.VERSION[0:2] >= (1, 8): from django.db.backends.base.creation import BaseDatabaseCreation diff --git a/django_cassandra_engine/compat.py b/django_cassandra_engine/compat.py index 418dd8e..f97bd66 100644 --- a/django_cassandra_engine/compat.py +++ b/django_cassandra_engine/compat.py @@ -4,6 +4,7 @@ from dse import cqlengine from dse.cluster import Session from dse.cqlengine import columns, connection, CQLEngineException, query, management + from dse.cqlengine.connection import set_default_connection from dse.auth import PlainTextAuthProvider from dse.cqlengine.management import create_keyspace_simple, drop_keyspace from dse.cqlengine.models import ( @@ -16,6 +17,7 @@ from cassandra import cqlengine from cassandra.cluster import Session from cassandra.cqlengine import columns, connection, CQLEngineException, query, management + from cassandra.cqlengine.connection import set_default_connection from cassandra.auth import PlainTextAuthProvider from cassandra.cqlengine.management import create_keyspace_simple, drop_keyspace from cassandra.cqlengine.models import ( From bb4d42c7333181657a791bb577844c70a1e7ad24 Mon Sep 17 00:00:00 2001 From: Joao Medeiros Date: Thu, 7 May 2020 09:51:34 -0300 Subject: [PATCH 3/5] Change version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 969f5b1..37483be 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='django-cassandra-engine', - version='1.5.5-bgds-1', + version='1.6.0', author=meta.__author__, author_email=meta.__contact__, url=meta.__homepage__, From 84488e11bd1efeca6cc26422922bdc7734e3f50f Mon Sep 17 00:00:00 2001 From: Joao Medeiros Date: Fri, 8 May 2020 17:36:10 -0300 Subject: [PATCH 4/5] Add the ability to have consistency level This consistency level can be used on both DjangoCassandraModel and DjangoCassandraQuerySet --- django_cassandra_engine/compat.py | 2 + django_cassandra_engine/models/__init__.py | 47 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/django_cassandra_engine/compat.py b/django_cassandra_engine/compat.py index f97bd66..f1a2cf9 100644 --- a/django_cassandra_engine/compat.py +++ b/django_cassandra_engine/compat.py @@ -11,6 +11,7 @@ ModelMetaClass, ModelException, ColumnDescriptor, ModelDefinitionException, BaseModel, Model ) + from dse.cqlengine.statements import SelectStatement from dse.util import OrderedDict except ImportError: try: @@ -25,6 +26,7 @@ ModelDefinitionException, BaseModel, Model ) from cassandra.util import OrderedDict + from cassandra.cqlengine.statements import SelectStatement except ImportError: raise ImportError('You must install either dse-driver or ' + 'cassandra-driver!') diff --git a/django_cassandra_engine/models/__init__.py b/django_cassandra_engine/models/__init__.py index 23f0518..126cd32 100644 --- a/django_cassandra_engine/models/__init__.py +++ b/django_cassandra_engine/models/__init__.py @@ -17,7 +17,7 @@ from ..compat import (BaseModel, ColumnDescriptor, ModelDefinitionException, ModelException, ModelMetaClass, OrderedDict, columns, - query) + query, SelectStatement) from .constants import ORDER_BY_WARN, ORDER_BY_ERROR_HELP, PK_META_MISSING_HELP from . import django_field_methods from . import django_model_methods @@ -656,6 +656,45 @@ def __init__(self, *args, **kwargs): super(query.ModelQuerySet, self).__init__(*args, **kwargs) self._allow_filtering = True self.query = StubQuery(model=self.model) + self.consistency_level_read = self._get_consistency_level_read() + self.consistency_level_write = self._get_consistency_level_write() + + def _get_consistency_level_read(self): + return self._get_consistency_level("_cassandra_consistency_level_read") + + def _get_consistency_level_write(self): + return self._get_consistency_level("_cassandra_consistency_level_write") + + def _get_consistency_level(self, field_name): + if hasattr(self.model, field_name): + return getattr(self.model, field_name) + return None + + def _execute(self, statement): + """ + If there is a default consistency level for read or write and the consistency + is not specified we will update this consistency before the _execute call and + after the result is processed we will reset again the consistency to avoid + confusion with the .consistency() usage. + """ + consistency_changed = False + if self._consistency is None: + if isinstance(statement, SelectStatement): + if self.consistency_level_read is not None: + self._consistency = self.consistency_level_read + consistency_changed = True + else: + if self.consistency_level_write is not None: + self._consistency = self.consistency_level_write + consistency_changed = True + + result = super(query.ModelQuerySet, self)._execute(statement) + if not consistency_changed: + return result + + if consistency_changed: + self._consistency = None + return result def _select_fields(self): if self._defer_fields or self._only_fields: @@ -803,6 +842,8 @@ def __init__(self, *args, **kwargs): new_method = partial(method, self) setattr(self, method_name, new_method) + self._set_consistency_level() + def __hash__(self): if self._get_pk_val() is None: raise TypeError("Model instances without primary key value are unhashable") @@ -853,3 +894,7 @@ def _get_explicit_pk_column(cls): return list(six.itervalues(cls._primary_keys))[0] except IndexError: return None + + def _set_consistency_level(self): + if hasattr(self, "_cassandra_consistency_level_write"): + self.consistency(self._cassandra_consistency_level_write) From 2c7ef9522cfcb0fc4e5aa159f28c14b89a719c9e Mon Sep 17 00:00:00 2001 From: Joao Medeiros Date: Fri, 8 May 2020 17:38:16 -0300 Subject: [PATCH 5/5] Correct version to not be a fixed value --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 37483be..5ea8dd3 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='django-cassandra-engine', - version='1.6.0', + version='.'.join(map(str, meta.__version__)), author=meta.__author__, author_email=meta.__contact__, url=meta.__homepage__,