diff --git a/.bumpversion.toml b/.bumpversion.toml index 2106aa5..3e5cbc9 100644 --- a/.bumpversion.toml +++ b/.bumpversion.toml @@ -1,5 +1,5 @@ [tool.bumpversion] -current_version = "0.0.2" +current_version = "0.0.3" parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" serialize = ["{major}.{minor}.{patch}"] search = "{current_version}" diff --git a/README.md b/README.md index eb3c87f..8908070 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Configuration for [confluent_kafka.schema_registry.SchemaRegistryClient](https:/ Default: `django_kafka.error_handlers.ClientErrorHandler` This is an `error_cb` hook (see [Kafka Client Configuration](https://docs.confluent.io/platform/current/clients/confluent-kafka-python/html/index.html#kafka-client-configuration) for reference). -It is triggered for client global errors and in case of fatal error it raises `DjangoKafkaException`. +It is triggered for client global errors and in case of fatal error it raises `DjangoKafkaError`. ## Bidirectional data sync with no infinite event loop. diff --git a/django_kafka/__init__.py b/django_kafka/__init__.py index 067b742..e792442 100644 --- a/django_kafka/__init__.py +++ b/django_kafka/__init__.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) -__version__ = "0.0.2" +__version__ = "0.0.3" __all__ = [ "autodiscover", diff --git a/django_kafka/consumer.py b/django_kafka/consumer.py index 77d20e3..e91b049 100644 --- a/django_kafka/consumer.py +++ b/django_kafka/consumer.py @@ -92,4 +92,4 @@ def commit_offset(self, msg: cimpl.Message): self.store_offsets(msg) def handle_error(self, error): - logger.error(error) + logger.error(error, exc_info=True) diff --git a/django_kafka/models.py b/django_kafka/models.py index ebb106d..c460e2c 100644 --- a/django_kafka/models.py +++ b/django_kafka/models.py @@ -37,12 +37,23 @@ class Meta: abstract = True base_manager_name = "objects" - def save(self, **kwargs): - if "update_fields" not in kwargs: + def save( + self, + force_insert=False, + force_update=False, + using=None, + update_fields=None, + ): + if update_fields is None: self.kafka_skip = False - elif "kafka_skip" not in kwargs["update_fields"]: + elif "kafka_skip" not in update_fields: self.kafka_skip = False - kwargs["update_fields"] = ["kafka_skip", *kwargs["update_fields"]] - - super().save(**kwargs) + update_fields = ["kafka_skip", *update_fields] + + super().save( + force_insert=force_insert, + force_update=force_update, + using=using, + update_fields=update_fields, + ) diff --git a/django_kafka/tests/test_models.py b/django_kafka/tests/test_models.py index 718d401..92ff303 100644 --- a/django_kafka/tests/test_models.py +++ b/django_kafka/tests/test_models.py @@ -12,41 +12,44 @@ def test_save_update_fields_not_in_kwargs(self, super_mock): """ kafka_skip should be set to False when update_fields is not provided """ - save_kwargs = {} instance = self.model(pk=1, kafka_skip=True) - instance.save(**save_kwargs) + instance.save() # save sets kafka_skip value to False self.assertFalse(instance.kafka_skip) # didn't forget to call super super_mock.assert_called_once_with() - # save kwargs are not changed - super_mock.return_value.save.assert_called_once_with(**save_kwargs) + # no update_fields set + super_mock.return_value.save.assert_called_once_with( + force_insert=False, + force_update=False, + using=None, + update_fields=None, + ) @patch("django_kafka.models.super") def test_save_update_fields_in_kwargs_without_kafka_skip(self, super_mock): """ kafka_skip should be set to False when update_fields does not contain kafka_skip """ - save_kwargs = { - "update_fields": ["some_field"], - } instance = self.model(pk=1, kafka_skip=True) - instance.save(**save_kwargs) + update_fields = ["some_fields"] + + instance.save(update_fields=update_fields) # save sets kafka_skip value to False self.assertFalse(instance.kafka_skip) # didn't forget to call super super_mock.assert_called_once_with() - # kafka_skip added to the update fields + # kafka_skip added to update_fields super_mock.return_value.save.assert_called_once_with( - **{ - **save_kwargs, - "update_fields": ["kafka_skip", *save_kwargs["update_fields"]], - }, + force_insert=False, + force_update=False, + using=None, + update_fields=["kafka_skip", *update_fields], ) @patch("django_kafka.models.super") @@ -54,19 +57,23 @@ def test_save_update_fields_in_kwargs_with_kafka_skip(self, super_mock): """ kafka_skip should not be changed if provided in update_fields """ - save_kwargs = { - "update_fields": ["some_field", "kafka_skip"], - } + update_fields = ["some_field", "kafka_skip"] + instance = self.model(pk=1, kafka_skip=True) - instance.save(**save_kwargs) + instance.save(update_fields=update_fields) # save does not change kafka_skip value self.assertTrue(instance.kafka_skip) # didn't forget to call super super_mock.assert_called_once_with() - # save kwargs are not changed - super_mock.return_value.save.assert_called_once_with(**save_kwargs) + # update_fields are not changed + super_mock.return_value.save.assert_called_once_with( + force_insert=False, + force_update=False, + using=None, + update_fields=update_fields, + ) @patch("django_kafka.models.super") def test_queryset_update_sets_kafka_skip(self, super_mock): diff --git a/pyproject.toml b/pyproject.toml index b435853..a322730 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "django-kafka" -version = "0.0.2" +version = "0.0.3" dependencies = [ "django>=4.0,<6.0", "confluent-kafka[avro, schema-registry]==2.4.0"