klen / klen/mixer

Issues with `mixer.SKIP`

Open
#122 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
953
Forks
91
PR merge metrics
No merged PRs in 30d

Description

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:

```python
# 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 (): 'object' object has no attribute '_sa_instance_state'
```

I assume this is a bug?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with tests/test_main.py around lines 287-291 to understand the existing mixer.SKIP behavior, then inspect mixer/backend/sqlalchemy.py at the postprocess location shown in the traceback. Reproduce the ReportMeta example from the issue and determine the expected SQLAlchemy behavior; done means SKIP no longer raises the shown error and its supported use is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlalchemy
Domain
databases, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.