Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SharedDataMiddleware respect order of exports #1197

Closed
wants to merge 0 commits into from

Conversation

@snoack
Copy link
Contributor

@snoack snoack commented Nov 19, 2017

The SharedDataMiddleware (and serving.run_simple(static_files=...) respectively) takes a dict, mapping file and directory names in the URL to files, directories or modules on disk. However, there are no dict-lookups involved in that logic, but instead dict item's are iterated, until a first match is found. But since dict items are retrieved in arbitrary order, the behavior is unpredictable, in scenarios like this:

serving.run_simple(static_files={
  '/static/': static_files_dir,
  '/': os.path.join(static_files_dir, 'index.html')
})

If the key / is yielded first, all requests resolve to index.html. Even using an OrderedDict doesn't help, since the SharedDataMiddleware internally creates another dict.

It seems to make most sense to just use lists, both to be passed in when using the API, and for the internal data structure. However, for backwards compatibility I keep supporting dict-like objects as well, in this PR.

@davidism
Copy link
Member

@davidism davidism commented Nov 29, 2017

Would you rebase against master? We fixed the tests.

@davidism
Copy link
Member

@davidism davidism commented Dec 4, 2017

Wait, what happened? I rebased and pushed to your branch and it wiped all the changes and closed it. There's no option to reopen.

@davidism
Copy link
Member

@davidism davidism commented Dec 4, 2017

OK, sorry, I messed up and pushed the rebase without your changes, and GitHub won't let me push again because it thinks the pr is closed(?). I'll make a new PR with your commits.

@davidism
Copy link
Member

@davidism davidism commented Dec 4, 2017

Might be related to having the commits on master instead of a separate branch.

@davidism davidism added this to the 0.13 milestone Dec 5, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants