Skip to content

Commit

Permalink
Fix #140: TypeError: sql_flush() got an unexpected keyword argument
Browse files Browse the repository at this point in the history
  • Loading branch information
r4fek committed May 19, 2021
1 parent 5dd1927 commit 82472d3
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 93 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required

language: python
python:
- "3.7"
- "3.8"

before_script:
- echo "deb http://www.apache.org/dist/cassandra/debian 40x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
Expand All @@ -14,10 +14,12 @@ before_script:

env:
matrix:
- TOX_ENV=py37-django21
- TOX_ENV=py37-django22
- TOX_ENV=py37-django30
- TOX_ENV=py37-djangomaster
- TOX_ENV=django21
- TOX_ENV=django22
- TOX_ENV=django30
- TOX_ENV=django31
- TOX_ENV=django32
- TOX_ENV=djangomaster
global:
- CASS_DRIVER_NO_CYTHON=1
- CASS_HOST=127.0.0.1
Expand All @@ -44,4 +46,4 @@ install:
- pip3 install tox-travis lz4

script:
- wait-for-it 127.0.0.1:9042 -- tox -e $TOX_ENV
- wait-for-it 127.0.0.1:9042 -t 120 -- tox -e $TOX_ENV
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7
FROM python:3.8
ENV PYTHONUNBUFFERED=1
ENV CASS_HOST=cassandra
RUN apt-get -y update
Expand Down
2 changes: 1 addition & 1 deletion django_cassandra_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Do not forget to change version number in mkdocs.yml also!
__version__ = (1, 6, 1)
__version__ = (1, 6, 2)
__author__ = "Rafał Furmański"
__contact__ = "[email protected]"
__homepage__ = "http://github.com/r4fek/django-cassandra-engine"
Expand Down
11 changes: 7 additions & 4 deletions django_cassandra_engine/base/operations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db.backends.base.operations import BaseDatabaseOperations

from django_cassandra_engine.utils import get_cassandra_connection


Expand Down Expand Up @@ -29,10 +30,9 @@ def prep_for_iexact_query(self, value):
"""
return value

def sql_flush(self, style, tables, sequences, allow_cascade=False):
def sql_flush(self, style, tables, *args, **kwargs):
"""
Truncate all existing tables in current keyspace.
:returns: an empty list
"""

Expand All @@ -44,8 +44,11 @@ def sql_flush(self, style, tables, sequences, allow_cascade=False):
return cql_list
return []

def execute_sql_flush(self, using, cql_list):
for cql in cql_list:
def execute_sql_flush(self, *args):
# In previous django versions first parameter was `using` and second `sql_list`.
# In Django 3.1 only one parameter `sql_list` is present.
# One thing is certain though: last parameter is `sql_list`
for cql in args[-1]:
self.connection.connection.execute(cql)

def prepare_sql_script(self, sql):
Expand Down
43 changes: 26 additions & 17 deletions django_cassandra_engine/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
import logging
import inspect
import copy
import warnings
from operator import attrgetter
import collections
from functools import partial
from itertools import chain
from operator import attrgetter
import collections
import copy
import inspect
import logging
import warnings

import six
from django.conf import settings
from django.apps import apps
from django.conf import settings
from django.core import validators
from django.db.models.base import ModelBase
from django.utils.translation import ugettext_lazy as _
from django.db.models import options
from django.db.models.base import ModelBase
from django.utils.translation import gettext_lazy as _
import six

from ..compat import (BaseModel, ColumnDescriptor, ModelDefinitionException,
ModelException, ModelMetaClass, OrderedDict, columns,
query)
from .constants import ORDER_BY_WARN, ORDER_BY_ERROR_HELP, PK_META_MISSING_HELP
from . import django_field_methods
from . import django_model_methods

from ..compat import (
BaseModel,
ColumnDescriptor,
ModelDefinitionException,
ModelException,
ModelMetaClass,
OrderedDict,
columns,
query,
)
from . import django_field_methods, django_model_methods
from .constants import (
ORDER_BY_ERROR_HELP,
ORDER_BY_WARN,
PK_META_MISSING_HELP,
)

log = logging.getLogger(__name__)
_django_manager_attr_names = ('objects', 'default_manager', '_default_manager',
Expand Down
8 changes: 4 additions & 4 deletions django_cassandra_engine/models/django_field_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import warnings

from django import forms
from django.utils.functional import Promise
from django.utils.text import capfirst
from django.core import checks, exceptions
from django.utils.encoding import smart_text
from django.utils.deprecation import (
RemovedInNextVersionWarning as RemovedInDjango20Warning,
)
from django.utils.encoding import smart_str
from django.utils.functional import Promise
from django.utils.text import capfirst

NOT_IMPL_MSG = 'Method not available on Cassandra model fields'

Expand All @@ -21,7 +21,7 @@ def value_from_object(self, obj):

def value_to_string(self, obj):
# Taken from django.db.models.fields.__init__
return smart_text(self.value_from_object(obj))
return smart_str(self.value_from_object(obj))


def get_attname(self):
Expand Down
9 changes: 5 additions & 4 deletions django_cassandra_engine/sessions/backends/db.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from datetime import datetime
import logging

from django.contrib.sessions.backends import db
from django.contrib.sessions.backends.db import (
SessionStore as DjangoSessionStore
SessionStore as DjangoSessionStore,
)
from django.core.exceptions import SuspiciousOperation
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.contrib.sessions.backends import db

# monkey patch for Django versions older than 1.9
from django_cassandra_engine.sessions.models import Session as CassandraSession

db.Session = CassandraSession


Expand Down Expand Up @@ -52,7 +53,7 @@ def load(self):
if isinstance(e, SuspiciousOperation):
logger = logging.getLogger('django.security.%s' %
e.__class__.__name__)
logger.warning(force_text(e))
logger.warning(force_str(e))
self.create()
return {}

Expand Down
21 changes: 8 additions & 13 deletions django_cassandra_engine/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import inspect

import django
from django.conf import settings
from django.db import DEFAULT_DB_ALIAS
import django

from .compat import cqlengine

Expand Down Expand Up @@ -59,18 +59,13 @@ def get_installed_apps():
"""
Return list of all installed apps
"""
if django.VERSION >= (1, 7):
from django.apps import apps

return [
a.models_module
for a in apps.get_app_configs()
if a.models_module is not None
]
else:
from django.db import models

return models.get_apps()
from django.apps import apps

return [
a.models_module
for a in apps.get_app_configs()
if a.models_module is not None
]


def get_cql_models(app, connection=None, keyspace=None):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cassandra-driver>=3.13
cassandra-driver>=3.25
Django>=2.0
six>=1.6
7 changes: 3 additions & 4 deletions testproject/app/tests/test_databasewrapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from datetime import datetime

from app.models import ExampleModel, ExampleModel2
from django.core.management import call_command
from django.core.management.sql import sql_flush
from mock import Mock

from django_cassandra_engine.test import TestCase
from django_cassandra_engine.connection import CassandraConnection
from django_cassandra_engine.test import TestCase
from django_cassandra_engine.utils import (
get_cassandra_connection,
get_cql_models,
get_installed_apps,
get_cassandra_connection,
)
from app.models import ExampleModel, ExampleModel2


class DatabaseWrapperTestCase(TestCase):
Expand Down Expand Up @@ -52,7 +52,6 @@ def test_sql_flush_works(self):
interactive=False,
database=self.connection.alias,
skip_checks=True,
reset_sequences=False,
allow_cascade=False,
inhibit_post_migrate=True,
)
Expand Down
1 change: 0 additions & 1 deletion testproject/common/tests/test_django_cassandra_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def test_values_list_with_pk_can_return_multiple_pks(self):
]
self.assertEqual(len(all_things.values_list('pk')), len(expected))

@skipIf(django.VERSION[1] < 10, "For Django>1.10 only")
def test_private_fields_are_set(self):
private_fields = [
f.name for f in CassandraFamilyMember._meta.private_fields
Expand Down
11 changes: 5 additions & 6 deletions testproject/common/tests/test_drf.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import uuid
from datetime import datetime
from unittest import skipIf
import uuid

from rest_framework.test import APITestCase
import django
import six.moves.http_client
from rest_framework.test import APITestCase

try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse

from django_cassandra_engine.test import TestCase as CassandraTestCase
from common.models import (
CassandraFamilyMember,
CassandraThing,
CassandraThingMultiplePK,
CassandraFamilyMember,
)
from common.serializers import CassandraFamilyMemberSerializer

from django_cassandra_engine.test import TestCase as CassandraTestCase


class TestModelViewSet(APITestCase):

Expand All @@ -34,7 +35,6 @@ def setUp(self):
'data_abstract': 'TeXt',
}

@skipIf(django.VERSION[1] < 10, "For Django>1.10 only")
def test_create_thing2a(self):
response = self.client.post(self.url, self.data2a, format='json')
self.assertEqual(response.status_code, six.moves.http_client.CREATED)
Expand All @@ -47,7 +47,6 @@ def test_create_thing2a(self):
self.assertDictEqual(response.json(), self.data2a)
self.assertEqual(response.status_code, six.moves.http_client.OK)

@skipIf(django.VERSION[1] < 10, "For Django>1.10 only")
def test_create_thing2b(self):
response = self.client.post(self.url, self.data2b, format='json')
self.assertEqual(response.status_code, six.moves.http_client.CREATED)
Expand Down
16 changes: 8 additions & 8 deletions testproject/common/urls.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from django.conf.urls import include, url
from django.urls import include, re_path
from rest_framework import routers

from .views import (
ThingMultiplePKViewSet,
ThingMultiplePKListCreateAPIView,
ThingModelViewSet,
ThingMultiplePKListAPIView,
ThingModelViewSet
ThingMultiplePKListCreateAPIView,
ThingMultiplePKViewSet,
)

router = routers.DefaultRouter()
router.register(r'thing-modelviewset', ThingModelViewSet)

urlpatterns = [
url(r'^thing-viewset/$', ThingMultiplePKViewSet.as_view({'get': 'list'}), name='thing_viewset_api'),
url(r'^thing-listcreate/$', ThingMultiplePKListCreateAPIView.as_view(), name='thing_listcreate_api'),
url(r'^thing-listview/$', ThingMultiplePKListAPIView.as_view(), name='thing_listview_api'),
url(r'^', include(router.urls)),
re_path(r'^thing-viewset/$', ThingMultiplePKViewSet.as_view({'get': 'list'}), name='thing_viewset_api'),
re_path(r'^thing-listcreate/$', ThingMultiplePKListCreateAPIView.as_view(), name='thing_listcreate_api'),
re_path(r'^thing-listview/$', ThingMultiplePKListAPIView.as_view(), name='thing_listview_api'),
re_path(r'^', include(router.urls)),
]
8 changes: 2 additions & 6 deletions testproject/model_meta/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from unittest import skipIf

import django
from cassandra.cqlengine import columns as cassandra_columns
from django.apps import apps
from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import FieldDoesNotExist
from django.db.models.fields import Field
from django.db.models.options import IMMUTABLE_WARNING
from django.test import SimpleTestCase
from cassandra.cqlengine import columns as cassandra_columns

from model_meta.models import CassandraThing
from model_meta.results import TEST_RESULTS
import django


class OptionsBaseTests(SimpleTestCase):
Expand Down Expand Up @@ -157,7 +154,6 @@ def test_related_objects_include_hidden_local_only(self):
)


@skipIf(django.VERSION[1] < 10, "For Django>1.10 only")
class PrivateFieldsTests(OptionsBaseTests):

def test_private_fields(self):
Expand Down
4 changes: 2 additions & 2 deletions testproject/sessionsapp/tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.core.cache import InvalidCacheBackendError
from django.test.utils import override_settings
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from mock import Mock
import six

Expand Down Expand Up @@ -344,7 +344,7 @@ def test_session_str(self):
session_key = self.session.session_key
s = self.model.objects.get(session_key=session_key)

self.assertEqual(force_text(s), session_key)
self.assertEqual(force_str(s), session_key)

def test_session_get_decoded(self):
"""
Expand Down
Loading

0 comments on commit 82472d3

Please sign in to comment.