Skip to content

Commit

Permalink
Remove the is_obsolete attribute from the StoredLibrary model
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed May 15, 2024
1 parent d807671 commit 9a13447
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ class Migration(migrations.Migration):
("builtin", models.BooleanField(default=False)),
("objects_meta", models.JSONField()),
("dependencies", models.JSONField(null=True)),
("is_obsolete", models.BooleanField(default=False)),
("is_loaded", models.BooleanField(default=False)),
("hash_checksum", models.CharField(max_length=64)),
("content", models.TextField()),
Expand Down
14 changes: 0 additions & 14 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class Meta:


class StoredLibrary(LibraryMixin):
is_obsolete = models.BooleanField(default=False)
is_loaded = models.BooleanField(default=False)
hash_checksum = models.CharField(max_length=64)
content = models.TextField()
Expand Down Expand Up @@ -152,19 +151,6 @@ def store_library_content(cls, library_content: bytes) -> "StoredLibrary | None"
urn=urn, locale=locale, version=version
).exists()

library_matches = [*StoredLibrary.objects.filter(urn=urn, locale=locale)]
if any(library.version >= version for library in library_matches):
# The library isn't stored if it's obsolete due to be a too old version of itself.
err = "A library with the urn '{}', a locale '{}' with a superior superior or equal to {} is already stored in the database.".format(
urn, locale, version
)
logger.error("Error while loading library content", error=err)
raise ValueError(err)

for library in library_matches:
library.is_obsolete = True
library.save() # If a user delete a library from the library store we must set the is_obsolete value of its most recent obsolete version to False.

objects_meta = {
key: len(value) for key, value in library_data["objects"].items()
}
Expand Down
2 changes: 1 addition & 1 deletion backend/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def check_and_import_dependencies(self):
if not LoadedLibrary.objects.filter(urn=dependency_urn).exists():
# import_library_view(get_library(dependency))
dependency = StoredLibrary.objects.get(
urn=dependency_urn, is_obsolete=False
urn=dependency_urn
) # We only fetch by URN without thinking about what locale, that may be a problem in the future.
error_msg = dependency.load()
if error_msg is not None:
Expand Down
2 changes: 1 addition & 1 deletion backend/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StoredLibraryViewSet(BaseModelViewSet):
# solve issue with URN containing dot, see https://stackoverflow.com/questions/27963899/django-rest-framework-using-dot-in-url
lookup_value_regex = r"[\w.:-]+"
model = StoredLibrary
queryset = StoredLibrary.objects.filter(is_obsolete=False)
queryset = StoredLibrary.objects.all()

filterset_fields = ["urn", "locale", "version", "packager", "provider"]
search_fields = ["name", "description", "urn"]
Expand Down
1 change: 0 additions & 1 deletion documentation/architecture/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ namespace ReferentialObjects {
}
class StoredLibrary {
+BooleanField is_obsolete
+BooleanField is_loaded
+CharField hash_checksum
+TextField content
Expand Down

0 comments on commit 9a13447

Please sign in to comment.