Cybirical / django-bulk-load

Load large batches of Django models into the database
MIT License
0 stars 0 forks source link

Unable to Process Models with Generated Fields #1

Open jrester-cyb opened 3 weeks ago

jrester-cyb commented 3 weeks ago

I have a model that is failing to be processed due to having a GeneratedField on it. Anytime I attempt it I receive the following error: File "/usr/local/lib/python3.10/dist-packages/django_bulk_load/bulk_load.py", line 408, in bulk_upsert_models return bulk_load_models_with_queries( File "/usr/local/lib/python3.10/dist-packages/django_bulk_load/bulk_load.py", line 115, in bulk_load_models_with_queries loading_table_name = create_temp_table_and_load( File "/usr/local/lib/python3.10/dist-packages/django_bulk_load/bulk_load.py", line 59, in create_temp_table_and_load tsv_buffer = models_to_tsv_buffer(models, fields, connection=connection) File "/usr/local/lib/python3.10/dist-packages/django_bulk_load/django.py", line 71, in models_to_tsv_buffer field_val = django_field_to_value(obj, include_field, connection) File "/usr/local/lib/python3.10/dist-packages/django_bulk_load/django.py", line 57, in _default_model_to_value field_val = field.pre_save(model, add=model._state.adding) File "/usr/local/lib/python3.10/dist-packages/django/db/models/fields/__init__.py", line 986, in pre_save return getattr(model_instance, self.attname) File "/usr/local/lib/python3.10/dist-packages/django/db/models/query_utils.py", line 216, in __get__ raise AttributeError( AttributeError: Cannot read a generated field from an unsaved model.

jrester-cyb commented 2 weeks ago

I have added a check to the get_model_fields method. It is now excluding any field that is an instance of a GeneratedField.