Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null values for contact id on resource downloads #1180

Merged
merged 4 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions salesforce/migrations/0083_alter_resourcedownload_contact_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2021-06-29 15:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('salesforce', '0082_partner_partnership_level'),
]

operations = [
migrations.AlterField(
model_name='resourcedownload',
name='contact_id',
field=models.CharField(default='', max_length=100, null=True),
),
]
18 changes: 18 additions & 0 deletions salesforce/migrations/0084_alter_resourcedownload_contact_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2021-06-29 15:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('salesforce', '0083_alter_resourcedownload_contact_id'),
]

operations = [
migrations.AlterField(
model_name='resourcedownload',
name='contact_id',
field=models.CharField(blank=True, max_length=100, null=True),
),
]
2 changes: 1 addition & 1 deletion salesforce/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ResourceDownload(models.Model):
last_access = models.DateTimeField()
number_of_times_accessed = models.IntegerField()
resource_name = models.CharField(max_length=255, null=True, blank=False)
contact_id = models.CharField(max_length=100, blank=True, default='')
contact_id = models.CharField(max_length=100, null=True, blank=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contact_id = models.CharField(max_length=100, null=True, blank=True)
contact_id = models.CharField(max_length=100, default='', blank=True)

null=True on a string field causes inconsistent data types because the value can be either str or None. This adds complexity and maybe bugs, but can be solved by replacing null=True with default="".


def save(self, *args, **kwargs):
if not self.pk:
Expand Down