marshmallow-code / marshmallow-code/flask-marshmallow
'DummySession' object has no attribute 'query'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 887
- Forks
- 65
- Avg merge
- 7h 25m
- Merged PRs (30d)
- 3
Description
We have been using flask-marshmallow 0.6.0 with marshmallow-sqlalchemy 0.3.0 for some time now, and been quite happy. However, in trying to upgrade our packages we have encountered the error message above.
It appears that marshmallow-sqlalchemy is now trying to actually manage adding/merging the models with the session. Personally, I don't want that. I want marshmallow to handle the deserialization and leave it to me to decide when and how I want to add or merge the model with the session, as we have been doing for some time. I have suggested on their issue board where others had brought up the issue that it would be nice if their code just skipped the session management parts if the session was none (see https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues/62). If they did that, then you wouldn't need to have a DummySession class at all. I do not know how amenable they will be to that suggestion.
The alternative is unfortunately to have to make DummySession implement methods to avoid generating errors, but this requires not just the query method but then it would appear filter_by, one, and first.
Or perhaps there is an alternative workaround that you already have in place. If so, I would be anxious to hear it.
Thanks.
Oh the full traceback is
Traceback (most recent call last):
File "tests.py", line 245, in runTest
(obj, errors) = schema.loads(example_str[name])
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow/schema.py", line 564, in loads
return self.load(data, many=many, partial=partial)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow_sqlalchemy/schema.py", line 186, in load
return super(ModelSchema, self).load(data, _args, *_kwargs)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow/schema.py", line 542, in load
result, errors = self._do_load(data, many, partial=partial, postprocess=True)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow/schema.py", line 646, in _do_load
result = self._invoke_load_processors(POST_LOAD, result, many, original_data=data)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow/schema.py", line 767, in _invoke_load_processors
data=data, many=many, original_data=original_data)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow/schema.py", line 865, in _invoke_processors
data = utils.if_none(processor(data), data)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow_sqlalchemy/schema.py", line 169, in make_instance
instance = self.instance or self.get_instance(data)
File "/home/davism/Src/atsdb/venv/lib/python2.7/site-packages/marshmallow_sqlalchemy/schema.py", line 154, in get_instance
return self.session.query(
AttributeError: 'DummySession' object has no attribute 'query'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure from tests.py around line 245 and inspect marshmallow_sqlalchemy/schema.py at lines 154, 169, and 186. Determine the expected behavior when deserializing with DummySession or no session, then add a regression test showing that loading data completes without the reported query error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python, sqlalchemy
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100