Skip to content
Snippets Groups Projects
Commit 263ef444 authored by Christophe Henry's avatar Christophe Henry
Browse files

bugfix: Prevent automatic source creation be performed if DB was not migrated...

bugfix: Prevent automatic source creation be performed if DB was not migrated yet (startinblox/djangoldp-packages/djangoldp#187)
parent 56bce0a8
No related branches found
No related tags found
No related merge requests found
from django.apps import AppConfig
from django.db import OperationalError
from django.db import OperationalError, connection
class DjangoldpConfig(AppConfig):
name = 'djangoldp'
......@@ -11,7 +10,17 @@ class DjangoldpConfig(AppConfig):
def create_local_source(self):
from djangoldp.models import LDPSource, Model
model_classes = {cls.__name__: cls for cls in Model.__subclasses__()}
model_classes = {}
db_tables = []
for cls in Model.__subclasses__():
model_classes[cls.__name__] = cls
db_tables.append(LDPSource.get_meta(cls, "db_table"))
# Check that all model's table already exists
existing_tables = connection.introspection.table_names()
if not all(db_table in existing_tables for db_table in db_tables):
return
for class_name in model_classes:
model_class = model_classes[class_name]
......@@ -19,7 +28,7 @@ class DjangoldpConfig(AppConfig):
continue
path = model_class.get_container_path().strip("/")
try:
existing_source = LDPSource.objects.get(federation=path)
LDPSource.objects.get(federation=path)
except LDPSource.DoesNotExist:
LDPSource.objects.create(federation=path, urlid=Model.absolute_url(model_class))
except OperationalError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment