Skip to content

Commit

Permalink
fix: adds unique_together
Browse files Browse the repository at this point in the history
and fixes nit
  • Loading branch information
pomegranited committed Jul 24, 2023
1 parent b1bae12 commit 5cc1c0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
35 changes: 35 additions & 0 deletions openedx_tagging/core/tagging/migrations/0004_auto_20230723_2001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.19 on 2023-07-24 01:01

from django.db import migrations, models
import openedx_learning.lib.fields


class Migration(migrations.Migration):

dependencies = [
('oel_tagging', '0003_auto_20230721_1238'),
]

operations = [
migrations.RemoveIndex(
model_name='tag',
name='oel_tagging_taxonom_89e779_idx',
),
migrations.RemoveIndex(
model_name='tag',
name='oel_tagging_taxonom_44e355_idx',
),
migrations.AlterField(
model_name='objecttag',
name='object_id',
field=openedx_learning.lib.fields.MultiCollationCharField(db_collations={'mysql': 'utf8mb4_unicode_ci', 'sqlite': 'NOCASE'}, db_index=True, editable=False, help_text='Identifier for the object being tagged', max_length=255),
),
migrations.AlterUniqueTogether(
name='tag',
unique_together={('taxonomy', 'value'), ('taxonomy', 'external_id')},
),
migrations.AddIndex(
model_name='objecttag',
index=models.Index(fields=['taxonomy', 'object_id'], name='oel_tagging_taxonom_aa24e6_idx'),
),
]
9 changes: 5 additions & 4 deletions openedx_tagging/core/tagging/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Tag(models.Model):
)

class Meta:
indexes = [
models.Index(fields=["taxonomy", "value"]),
models.Index(fields=["taxonomy", "external_id"]),
unique_together = [
["taxonomy", "external_id"],
["taxonomy", "value"],
]

def __repr__(self):
Expand Down Expand Up @@ -443,6 +443,7 @@ class ObjectTag(models.Model):
id = models.BigAutoField(primary_key=True)
object_id = case_insensitive_char_field(
max_length=255,
db_index=True,
editable=False,
help_text=_("Identifier for the object being tagged"),
)
Expand Down Expand Up @@ -484,6 +485,7 @@ class ObjectTag(models.Model):

class Meta:
indexes = [
models.Index(fields=["taxonomy", "object_id"]),
models.Index(fields=["taxonomy", "_value"]),
]

Expand Down Expand Up @@ -556,7 +558,6 @@ def tag_ref(self, tag_ref: str):
try:
self.tag = self.taxonomy.tag_set.get(pk=tag_ref)
self.value = self.tag.value
return
except (ValueError, Tag.DoesNotExist):
# This might be ok, e.g. if our taxonomy.allow_free_text, so we just pass through here.
# We rely on the caller to validate before saving.
Expand Down

0 comments on commit 5cc1c0e

Please sign in to comment.