Skip to content

Commit

Permalink
Set primary key to UUID to fix API bug
Browse files Browse the repository at this point in the history
While objects were routinely cleaned, the auto-incrementing ID field
went past the limit of IntegerField. The UUID field is unique and can
be used instead.
  • Loading branch information
madprime committed Dec 22, 2020
1 parent ad760a8 commit 78799a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions data_import/migrations/0025_auto_20201222_1934.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.13 on 2020-12-22 19:34

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [("data_import", "0024_auto_20201222_1757")]

operations = [
migrations.RemoveField(model_name="datafilekey", name="id"),
migrations.AlterField(
model_name="datafilekey",
name="key",
field=models.CharField(
default=uuid.uuid4,
max_length=36,
primary_key=True,
serialize=False,
unique=True,
),
),
]
8 changes: 4 additions & 4 deletions data_import/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class DataFileKey(models.Model):
"""

created = models.DateTimeField(auto_now_add=True)
key = models.CharField(max_length=36, blank=False, unique=True, default=uuid.uuid4)
key = models.CharField(
max_length=36, blank=False, unique=True, default=uuid.uuid4, primary_key=True
)
datafile_id = models.BigIntegerField()
ip_address = models.GenericIPAddressField(null=True)
access_token = models.CharField(max_length=64, null=True)
Expand Down Expand Up @@ -112,12 +114,10 @@ def generate_key(self, request):
Generate new link expiration key
"""
new_key = DataFileKey(datafile_id=self.id)
new_key.save()

if request:
# Log the entity that is requesting the key be generated
new_key.ip_address = get_ip(request)
new_key.save()

try:
new_key.access_token = request.query_params.get("access_token", None)
Expand All @@ -128,8 +128,8 @@ def generate_key(self, request):
except AttributeError:
# We do not have an accessing project
new_key.project_id = None
new_key.save()

new_key.save()
return new_key.key

@property
Expand Down

0 comments on commit 78799a9

Please sign in to comment.