From 76014b7eee497aa24e8dbb5389448f0245870ef8 Mon Sep 17 00:00:00 2001 From: farhan Date: Wed, 4 Oct 2023 10:21:32 +0500 Subject: [PATCH] fix: Fix test cases --- openedx_learning/core/publishing/api.py | 2 +- .../core/tagging/models/system_defined.py | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/openedx_learning/core/publishing/api.py b/openedx_learning/core/publishing/api.py index 6a425b8c..b4b701a2 100644 --- a/openedx_learning/core/publishing/api.py +++ b/openedx_learning/core/publishing/api.py @@ -91,7 +91,7 @@ def create_publishable_entity_version( version_num=version_num, title=title, created=created, - created_by=created_by, + created_by_id=created_by, ) Draft.objects.create( entity_id=entity_id, diff --git a/openedx_tagging/core/tagging/models/system_defined.py b/openedx_tagging/core/tagging/models/system_defined.py index 23180f6e..20ae1a1c 100644 --- a/openedx_tagging/core/tagging/models/system_defined.py +++ b/openedx_tagging/core/tagging/models/system_defined.py @@ -4,14 +4,12 @@ from __future__ import annotations import logging - from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ObjectDoesNotExist from django.db import models from openedx_tagging.core.tagging.models.base import Tag - from .base import Tag, Taxonomy log = logging.getLogger(__name__) @@ -88,7 +86,10 @@ def validate_value(self, value: str): Check if 'value' is part of this Taxonomy, based on the specified model. """ try: - self.tag_class_model.objects.get(**{f"{self.tag_class_value_field}__iexact": value}) + # See https://github.com/typeddjango/django-stubs/issues/1684 for why we need to ignore this. + self.tag_class_model.objects.get( # type: ignore[attr-defined] + **{f"{self.tag_class_value_field}__iexact": value} + ) return True except ObjectDoesNotExist: return False @@ -100,7 +101,10 @@ def tag_for_value(self, value: str): try: # First we look up the instance by value. # We specify 'iexact' but whether it's case sensitive or not on MySQL depends on the model's collation. - instance = self.tag_class_model.objects.get(**{f"{self.tag_class_value_field}__iexact": value}) + # See https://github.com/typeddjango/django-stubs/issues/1684 for why we need to ignore this. + instance = self.tag_class_model.objects.get( # type: ignore[attr-defined] + **{f"{self.tag_class_value_field}__iexact": value} + ) except ObjectDoesNotExist as exc: raise Tag.DoesNotExist from exc # Use the canonical value from here on (possibly with different case from the value given as a parameter) @@ -120,7 +124,10 @@ def validate_external_id(self, external_id: str): Check if 'external_id' is part of this Taxonomy. """ try: - self.tag_class_model.objects.get(**{f"{self.tag_class_key_field}__iexact": external_id}) + # See https://github.com/typeddjango/django-stubs/issues/1684 for why we need to ignore this. + self.tag_class_model.objects.get( # type: ignore[attr-defined] + **{f"{self.tag_class_key_field}__iexact": external_id} + ) return True except ObjectDoesNotExist: return False @@ -136,7 +143,10 @@ def tag_for_external_id(self, external_id: str): try: # First we look up the instance by external_id # We specify 'iexact' but whether it's case sensitive or not on MySQL depends on the model's collation. - instance = self.tag_class_model.objects.get(**{f"{self.tag_class_key_field}__iexact": external_id}) + # See https://github.com/typeddjango/django-stubs/issues/1684 for why we need to ignore this. + instance = self.tag_class_model.objects.get( # type: ignore[attr-defined] + **{f"{self.tag_class_key_field}__iexact": external_id} + ) except ObjectDoesNotExist as exc: raise Tag.DoesNotExist from exc value = getattr(instance, self.tag_class_value_field)