Skip to content

Commit e1a19aa

Browse files
Copilothumitos
andcommitted
Address code review feedback: fix imports and BuildConfig consistency
Co-authored-by: humitos <244656+humitos@users.noreply.github.com>
1 parent 054385c commit e1a19aa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

readthedocs/builds/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,11 @@ def save(self, *args, **kwargs): # noqa
863863
if previous is not None and self._config and self._config == previous.config:
864864
previous_pk = previous._config.get(self.CONFIG_KEY, previous.pk)
865865
self._config = {self.CONFIG_KEY: previous_pk}
866-
867-
# Populate the new readthedocs_yaml_data field
868-
# We only create a BuildConfig when we have actual config data (not a reference)
869-
if self._config and self.CONFIG_KEY not in self._config:
866+
# Clear readthedocs_yaml_data when using reference style
867+
self.readthedocs_yaml_data = None
868+
elif self._config and self.CONFIG_KEY not in self._config:
869+
# Populate the new readthedocs_yaml_data field
870+
# We only create a BuildConfig when we have actual config data (not a reference)
870871
# Use get_or_create to avoid duplicates and leverage the unique constraint
871872
build_config, created = BuildConfig.objects.get_or_create(
872873
data=self._config

readthedocs/builds/tests/test_buildconfig.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import django_dynamic_fixture as fixture
44
import pytest
5+
from django.db import IntegrityError
56

67
from readthedocs.builds.models import Build
78
from readthedocs.builds.models import BuildConfig
9+
from readthedocs.builds.models import Version
810
from readthedocs.projects.models import Project
911

1012

@@ -28,7 +30,6 @@ def test_buildconfig_unique_constraint(self):
2830
BuildConfig.objects.create(data=config_data)
2931

3032
# Try to create another with the same data - should raise IntegrityError
31-
from django.db import IntegrityError
3233
with pytest.raises(IntegrityError):
3334
BuildConfig.objects.create(data=config_data)
3435

@@ -117,8 +118,6 @@ def test_build_without_config_does_not_create_buildconfig(self):
117118

118119
def test_build_with_config_reference_uses_same_buildconfig(self):
119120
"""Test that a Build with config reference (old style) doesn't create a new BuildConfig."""
120-
from readthedocs.builds.models import Version
121-
122121
project = fixture.get(Project)
123122
version = fixture.get(Version, project=project)
124123
config_data = {"build": {"os": "ubuntu-22.04"}}

0 commit comments

Comments
 (0)