paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
391 stars 67 forks source link

Argument called `instance` can't be passed to object creation with G #53

Closed ilonajulczuk closed 9 years ago

ilonajulczuk commented 10 years ago

Argument called instance can't be passed to object creation with G. I have a class with instance field and there is a name collision in

self.set_data_for_a_field(model_class, instance, field, persist_dependencies=persist_dependencies, **configuration)

Whole traceback:

In [12]: G(AdminInstanceRole, instance=instance, admin=admin, role=role)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-edd08ece1c23> in <module>()
----> 1 G(AdminInstanceRole, instance=instance, admin=admin, role=role)

/usr/local/lib/python2.7/dist-packages/django_dynamic_fixture/__init__.pyc in get(model, shelve, n, **kwargs)
    104     d = fixture(**kwargs)
    105     if n == 1:
--> 106         return d.get(model, shelve=shelve, **kwargs)
    107     instances = []
    108     for _ in range(n):

/usr/local/lib/python2.7/dist-packages/django_dynamic_fixture/ddf.pyc in get(self, model_class, shelve, named_shelve, **kwargs)
    514         :named_shelve: restore configuration saved in DDF library with a name.
    515         """
--> 516         instance = self.new(model_class, shelve=shelve, named_shelve=named_shelve, **kwargs)
    517         if is_model_abstract(model_class):
    518             raise InvalidModelError(get_unique_model_name(model_class))

/usr/local/lib/python2.7/dist-packages/django_dynamic_fixture/ddf.pyc in new(self, model_class, shelve, named_shelve, persist_dependencies, **kwargs)
    441             if is_key_field(field) and 'id' not in configuration: continue
    442             if field.name in self.ignore_fields: continue
--> 443             self.set_data_for_a_field(model_class, instance, field, persist_dependencies=persist_dependencies, **configuration)
    444         number_of_pending_fields = len(self.pending_fields)
    445         # For Copier fixtures: dealing with pending fields that need to receive values of another fields.

TypeError: set_data_for_a_field() got multiple values for keyword argument 'instance'

Thanks.

paulocheque commented 10 years ago

I naively thought that kind of error would never happen!

I will rename it.

In the mean time you can create a copy for the wrapper with a distinct variable name.

ilonajulczuk commented 10 years ago

@paulocheque thanks :), I will wait for an updates and change pip dependency when the change is available.

Currently my workaround is just using normal django orm model creation for that, but I have a few models with instance field and would like to use django_dynamic_fixture with them too.

paulocheque commented 9 years ago

A little late but fixed: https://github.com/paulocheque/django-dynamic-fixture/commit/c95ee2edf7b38d351f6d451dee012cd6cf523d58

Release: https://pypi.python.org/pypi/django-dynamic-fixture/1.8.1

ilonajulczuk commented 9 years ago

Great, thanks a lot!