Skip to content

Django3: delete old JSONField and use the new ones #8869

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

Merged
merged 6 commits into from
Feb 14, 2022
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
22 changes: 22 additions & 0 deletions readthedocs/builds/migrations/0040_remove_old_jsonfields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.2.11 on 2022-01-31 12:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('builds', '0039_migrate_config_data'),
]

operations = [
migrations.RemoveField(
model_name='build',
name='_config',
),
migrations.RenameField(
model_name='build',
old_name='_config_json',
new_name='_config',
),
]
4 changes: 1 addition & 3 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
ModificationDateTimeField,
)
from django_extensions.db.models import TimeStampedModel
from jsonfield import JSONField
from polymorphic.models import PolymorphicModel

import readthedocs.builds.automation_actions as actions
Expand Down Expand Up @@ -662,8 +661,7 @@ class Build(models.Model):
null=True,
blank=True,
)
_config = JSONField(_('Configuration used in the build'), default=dict)
_config_json = models.JSONField(_('Configuration used in the build'), default=dict)
_config = models.JSONField(_('Configuration used in the build'), default=dict)

length = models.IntegerField(_('Build Length'), null=True, blank=True)

Expand Down
40 changes: 40 additions & 0 deletions readthedocs/integrations/migrations/0010_remove_old_jsonfields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 3.2.11 on 2022-01-31 12:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('integrations', '0009_migrate_headers_data'),
]

operations = [
migrations.RemoveField(
model_name='httpexchange',
name='request_headers',
),
migrations.RemoveField(
model_name='httpexchange',
name='response_headers',
),
migrations.RemoveField(
model_name='integration',
name='provider_data',
),
migrations.RenameField(
model_name='httpexchange',
old_name='request_headers_json',
new_name='request_headers',
),
migrations.RenameField(
model_name='httpexchange',
old_name='response_headers_json',
new_name='response_headers',
),
migrations.RenameField(
model_name='integration',
old_name='provider_data_json',
new_name='provider_data',
),
]
17 changes: 8 additions & 9 deletions readthedocs/integrations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.db import models, transaction
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from jsonfield import JSONField
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import JsonLexer
Expand Down Expand Up @@ -102,12 +101,15 @@ def from_requests_exchange(self, response, related_object):
:param related_object: Object to use for generic relationship.
"""
request = response.request
# NOTE: we need to cast ``request.headers`` and ``response.headers``
# because it's a ``requests.structures.CaseInsensitiveDict`` which is
# not JSON serializable.
obj = self.create(
related_object=related_object,
request_headers=request.headers or {},
request_headers=dict(request.headers) or {},
request_body=request.body or '',
status_code=response.status_code,
response_headers=response.headers,
response_headers=dict(response.headers),
response_body=response.text,
)
self.delete_limit(related_object)
Expand Down Expand Up @@ -144,17 +146,15 @@ class HttpExchange(models.Model):

date = models.DateTimeField(_('Date'), auto_now_add=True)

request_headers = JSONField(_('Request headers'))
request_headers_json = models.JSONField(
request_headers = models.JSONField(
_('Request headers'),
# Delete after deploy
null=True,
default=None,
)
request_body = models.TextField(_('Request body'))

response_headers = JSONField(_('Request headers'))
response_headers_json = models.JSONField(
response_headers = models.JSONField(
_('Request headers'),
# Delete after deploy
null=True,
Expand Down Expand Up @@ -298,8 +298,7 @@ class Integration(models.Model):
max_length=32,
choices=INTEGRATIONS,
)
provider_data = JSONField(_('Provider data'), default=dict)
provider_data_json = models.JSONField(_('Provider data'), default=dict)
provider_data = models.JSONField(_('Provider data'), default=dict)
exchanges = GenericRelation(
'HttpExchange',
related_query_name='integrations',
Expand Down
4 changes: 4 additions & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ drf-flex-fields==0.9.7
drf-extensions==0.7.1

django-vanilla-views==3.0.0

# This module is only used on migrations. We are now using Django's official
# JSONField. We should probably squash these migrations and remove this
# dependency as well.
Copy link
Member

Choose a reason for hiding this comment

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

👍

jsonfield==3.1.0

requests==2.27.1
Expand Down