klen / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Other
939 stars 96 forks source link

Issues with `mixer.SKIP` #122

Open multimeric opened 5 years ago

multimeric commented 5 years ago

I noticed in the tests, and the source code, that there is a mixer.SKIP property that can be used to skip the generation of certain fields: https://github.com/klen/mixer/blob/6af15d5e65d8a2ee8185f7777bf095d611ba13ae/tests/test_main.py#L287-L291.

My first question is, why is this not documented? It seems to be tested so it must work for normal use.

My second question involves using SKIP with the SQLAlchemy backend. I've noticed if you try to use these together, you'll get an error:

# I think the model you use here can be anything that has a relationship field
x = mix.blend(models.ReportMeta, report_meta_key='key_1', report_meta_value='1', report=mix.SKIP)

And you get:

Traceback (most recent call last):
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/mixer/main.py", line 568, in blend
    return type_mixer.blend(**values)
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/mixer/main.py", line 140, in blend
    target = self.postprocess(target, postprocess_values)
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/mixer/backend/sqlalchemy.py", line 76, in postprocess
    setattr(target, name, value)
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 262, in __set__
    instance_state(instance), instance_dict(instance), value, None
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 975, in set
    value = self.fire_replace_event(state, dict_, value, old, initiator)
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 998, in fire_replace_event
    state, value, previous, initiator or self._replace_token
  File "/home/michael/Programming/MegaQC/venv/lib/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 1407, in emit_backref_from_scalar_set_event
    instance_state(child),
AttributeError: Mixer (<class 'megaqc.model.models.ReportMeta'>): 'object' object has no attribute '_sa_instance_state'

I assume this is a bug?

mcbloch commented 3 years ago

I'll up the fact that it not being documented was a real struggle.