rvinzent / django-dynamic-models

Dynamic Django models allow users to define, edit, and populate their own database schema.
MIT License
158 stars 47 forks source link

Not working if (Memcached) Cache offline #43

Open pyMan opened 3 years ago

pyMan commented 3 years ago

Hi.

Python 3.8.x

django 2.2.x django_dynamic_models 0.3.0

I set settings.CACHE to use memcached. If the memcached service is offline for any reason, simplest things like creating e FieldSchema fail. As soon as I start the memcached service, things work.

I do not understand exactly how the missing cache backend can affect things. I see this library makes use of cache, but it should be just for performance reason.

from dynamic_models.models import ModelSchema, FieldSchema

car_schema = ModelSchema.objects.create(name='Car')
car_model_field = FieldSchema.objects.create(model_schema=car_schema, name='test', data_type='character')  ### raise error

Traceback

Traceback (most recent call last):
  File ".\test.py", line 31, in <module>
    FieldSchema.objects.create(model_schema = model_schema, name = "test", data_type = 'character')
  File "C:\Users\.....\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\.....\lib\site-packages\django\db\models\query.py", line 422, in create
    obj.save(force_insert=True, using=self.db)
  File "C:\Users\.....\lib\site-packages\dynamic_models\models.py", line 95, in save
    self._schema_editor.update_column(model, field)
  File "C:\Users\.....\lib\site-packages\dynamic_models\schema.py", line 39, in update_column
    self.add_column(model, new_field)
  File "C:\Users\.....\lib\site-packages\dynamic_models\schema.py", line 44, in add_column
    editor.add_field(model, field)
  File "C:\Users\.....\lib\site-packages\sql_server\pyodbc\schema.py", line 635, in add_field
    if field.many_to_many and field.remote_field.through._meta.auto_created:
AttributeError: 'NoneType' object has no attribute 'many_to_many'

Thanks for help

rvinzent commented 3 years ago

The caching has been buggy in the past and needs to be removed / reworked 🙂

That was the last thing I wanted to do before the next release.