Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Fix inbox_get method of DefaultBackend #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix inbox_get method of DefaultBackend #32

wants to merge 3 commits into from

Conversation

byrman
Copy link

@byrman byrman commented Sep 4, 2016

While working with the REST API, I ran into a problem with the inbox-detail view.

The inbox-list view serializes all messages in a user's inbox. The "id" values in the JSON response are primary keys of Message objects (when using the DefaultBackend). The /inbox/{id}/ endpoint provides a detail view of those messages. In the process, however, the "id" (of a message) is inadvertently used as the primary key of an Inbox object:

https://github.com/evonove/django-stored-messages/blob/master/stored_messages/backends/default/backend.py#L43

Why doesn't this show up in the current tests? Message and Inbox objects are often created in pairs. If the database starts numbering both tables at 1, corresponding objects will have the same primary key. Of course, you cannot rely on this.

I created a test that demonstrates the problem. By sending the same message to two users, the primary keys of the underlying message and inbox tables are no longer synchronous. In this situation, user2 can no longer obtain a detail view if user1 marks his message as read.

While writing my test, I noticed that api functions such as "add_message_for" are not using the STORAGE_BACKEND overridden by TestRESTApiWithRedis. I fixed this as well, by doing an inline import. NB: views.py is already doing it this way, so this fix is consistent with that.

@byrman
Copy link
Author

byrman commented Sep 4, 2016

Not sure how to read this output: https://travis-ci.org/evonove/django-stored-messages/jobs/157436805. Flake8 under Python 3.5.2 is complaining about files I didn't touch?

@reinout
Copy link

reinout commented Sep 5, 2016

@byrman: since june this year (=after the last time the checks were run) flake8/pyflakes added an extra error for undefined variables from a "star" import. See http://flake8.pycqa.org/en/latest/release-notes/2.6.0.html

So if you change the "ignore" line in the top-level tox.ini to:

ignore = F403,F405

... then the tests should run OK again.

@byrman
Copy link
Author

byrman commented Sep 5, 2016

Travis is happy again. Thanks, @reinout. Perhaps it's better to address the star imports, but that's something for another pull request (imho).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants