ModelDataset evaluates queryset during import
beniwohli opened this issue · comments
Specifically, DatasetMetaclass
evaluates the queryset twice:
if not opts.model and not opts.queryset:
raise NoObjectsException("You must set a model or non-empty "
"queryset for each Dataset subclass")
if opts.queryset:
queryset = opts.queryset
model = queryset.model
new_class.queryset = queryset
new_class.model = model
This can lead to hard to debug problems, e.g. when the database tables don't exist yet. Instead, these if-conditions could specifically check if the queryset is not None:
if not opts.model and opts.queryset is None:
raise NoObjectsException("You must set a model or non-empty "
"queryset for each Dataset subclass")
if opts.queryset is not None:
queryset = opts.queryset
model = queryset.model
new_class.queryset = queryset
new_class.model = model