You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Meta:
model = SomeModel
image_field = factory.django.ImageField(filename='registration.jpg', width=1, height=1)
When I try to create the object using SomeFactory.create() I get this traceback:
Traceback (most recent call last:
File "tests_frontend.py", line 351, in test_card_activation
registration = SomeFactory.create()
File "env/lib/python2.7/site-packages/factory/base.py", line 559, in create
return cls._generate(True, attrs)
File "env/lib/python2.7/site-packages/factory/base.py", line 484, in _generate
obj = cls._prepare(create, **attrs)
File "env/lib/python2.7/site-packages/factory/base.py", line 459, in _prepare
return cls._create(model_class, *args, **kwargs)
File "env/lib/python2.7/site-packages/factory/django.py", line 149, in _create
return manager.create(*args, **kwargs)
File "env/lib/python2.7/site-packages/django/db/models/manager.py", line 137, in create
return self.get_query_set().create(**kwargs)
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 377, in create
obj.save(force_insert=True, using=self.db)
File "env/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "env/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "env/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "env/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 911, in execute_sql
for sql, params in self.as_sql():
File "env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 872, in as_sql
for obj in self.query.objs
File "env/lib/python2.7/site-packages/django/db/models/fields/files.py", line 249, in pre_save
file.save(file.name, file, save=False)
File "env/lib/python2.7/site-packages/django/db/models/fields/files.py", line 90, in save
self._size = content.size
File "env/lib/python2.7/site-packages/django/db/models/fields/files.py", line 70, in _get_size
return self.file.size
File "env/lib/python2.7/site-packages/django/core/files/base.py", line 39, in _get_size
elif os.path.exists(self.file.name):
AttributeError: 'cStringIO.StringI' object has no attribute 'name'
I was expecting the instance would be created with an image
The text was updated successfully, but these errors were encountered:
Indeed, this is a known issue with factory.django.FileField and factory.django.ImageField that are implemented as post-build fields, thus not available in the field's save() method.
Given a factory with this code:
class SomeFactory(factory.DjangoModelFactory):
When I try to create the object using SomeFactory.create() I get this traceback:
I was expecting the instance would be created with an image
The text was updated successfully, but these errors were encountered: