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

fix(versioning): ensure get_previous_version returns previous version, not latest version #4083

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
2 changes: 1 addition & 1 deletion api/features/versioning/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_previous_version(self) -> typing.Optional["EnvironmentFeatureVersion"]:
self.__class__.objects.filter(
environment=self.environment,
feature=self.feature,
live_from__lt=timezone.now(),
live_from__lt=self.live_from or timezone.now(),
published_at__isnull=False,
)
.order_by("-live_from")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,36 @@ def test_get_previous_version_ignores_unpublished_version(
assert version_3.get_previous_version() == version_1


def test_get_previous_version_returns_previous_version_if_there_is_a_more_recent_previous_version(
feature: "Feature",
environment_v2_versioning: Environment,
admin_user: "FFAdminUser",
) -> None:
# Given
# The initial version created when enabling versioning_v2
version_0 = EnvironmentFeatureVersion.objects.get(
environment=environment_v2_versioning, feature=feature
)

# Now, let's create (and publish) 2 new versions
version_1 = EnvironmentFeatureVersion.objects.create(
environment=environment_v2_versioning, feature=feature
)
version_1.publish(admin_user)
version_2 = EnvironmentFeatureVersion.objects.create(
environment=environment_v2_versioning, feature=feature
)
version_2.publish(admin_user)

# When
previous_version = version_1.get_previous_version()

# Then
# The previous version for the first version we created should be the
# original version created when enabling versioning_v2
assert previous_version == version_0


def test_publish(
feature: "Feature",
project: "Project",
Expand Down