Skip to content

Commit

Permalink
The dependencies field is not a JSONField
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Apr 24, 2024
1 parent cb94245 commit d846d97
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _ready(self):

# Remove the 3 following lines after
"""from core.models import LoadedLibrary
for lib in LoadedLibrary.objects.all() :
for lib in StoredLibrary.objects.all() :
lib.delete()"""

start = time.perf_counter()
Expand Down
18 changes: 18 additions & 0 deletions backend/core/migrations/0010_alter_storedlibrary_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-04-24 14:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0009_loadedlibrary_alter_framework_library_and_more'),
]

operations = [
migrations.AlterField(
model_name='storedlibrary',
name='dependencies',
field=models.JSONField(null=True),
),
]
6 changes: 2 additions & 4 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Meta:
)
builtin = models.BooleanField(default=False)
objects_meta = models.JSONField()
dependencies = models.CharField(blank=False,null=True,max_length=16384)
dependencies = models.JSONField(null=True) # models.CharField(blank=False,null=True,max_length=16384)

def get_dependencies(self) -> List[str] : # We should add some kind of descriptor to LibaryMixin so that model_instance.dependencies directly returns a list instead of a string, using a function to get the desired value of a field is bad
return [] if self.dependencies is None else self.dependencies.split(" ")
Expand Down Expand Up @@ -169,9 +169,7 @@ def store_library_file(fname: str) -> Union[str,None] :
for key, value in library_data["objects"].items()
}

dependencies = library_data.get("dependencies")
if dependencies is not None :
dependencies = " ".join(dependencies) # Which means we have to make the URN format more restrictive so that an URN is considered invalid if it contains any kind of whitespace.
dependencies = library_data.get("dependencies") # I don't want whitespaces in URN anymore nontheless

library_objects = json.dumps(library_data["objects"])
StoredLibrary.objects.create(
Expand Down
2 changes: 1 addition & 1 deletion backend/library/libraries/critical_risk_matrix_3x3.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
urn: urn:intuitem:risk:library:critical_risk_matrix_3x3
locale: en
ref_id: critical_3x3
nam: Critical risk matrix 3x3
name: Critical risk matrix 3x3
description: Critical risk matrix 3x3
version: 1
provider: intuitem
Expand Down
1 change: 1 addition & 0 deletions backend/library/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Meta:
# objects_meta = serializers.JSONField()

class StoredLibraryDetailedSerializer(serializers.ModelSerializer):
dependencies = lambda dependencies: dependencies.split(" ")
class Meta:
model = StoredLibrary
fields = "__all__"
Expand Down

0 comments on commit d846d97

Please sign in to comment.