8000 Fix subdomain inheritance for nested blueprints. by confuzeus · Pull Request #4856 · pallets/flask · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix subdomain inheritance for nested blueprints. #4856

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

Closed

Conversation

confuzeus
Copy link
Contributor

When child blueprints are mounted onto parents, they don't inherit the subdomain set by the parent.

This PR ensures that routes in child blueprint will be available at the same subdomain set by the parent.

However, children can also specify their own subdomain if necessary.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

if bp_subdomain is None:
bp_subdomain = blueprint.subdomain

if state.subdomain is not None and bp_subdomain is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also consider what to do if state.subdomain is not None and bp_subdomain is not None. I think we should combine as state.bp (much like with the prefix). Would you expect it to work this way as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good point.

I thought that if both parent and child have subdomain set, it would be weird to combine. It makes sense for paths but subdomains in the form foo.bar.baz are rare.

For example if parent is bar and child is foo, we would get foo.bar.

But I can get this by supplying foo.bar in the child blueprint subdomain. So I went with the child overrides parent subdomain way that way the user can use a combined subdomain as needed.

Not sure this is a good idea though because some use cases might need them to be combined by default.

Another possible solution would be to introduce an extra parameter called something like "combine_subdomains". This will also allow different child blueprint to have different subdomain strategies. For example, foo can choose to be combined but baz can choose not to.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given it might confuse it is probably safest to raise a ValueError/RuntimeError then if both are set. (This would be raised during initialization and so isn't likely to cause any issues for existing apps)

Copy link
Contributor Author
@confuzeus confuzeus Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be an issue if the user wants to combine the subdomain anyway.

For example, parent blueprint's subdomain is bar then user wants child blueprint X to be available at "foo.bar" so he sets the subdomain. Then another blueprint Y needs to be at "baz.bar" so he sets the subdomain like that. But parent needs to be available at bar subdomain no matter what.

Raising ValueError would break this use case since both parent and child subdomains are set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had quite a bit of time to think about this, and to talk to others about their expectations. I think we should combine the subdomains (much like we do for the paths). I think this is the clearest expectation for a nested blueprint i.e. that the routes defined within it nest both by path and subdomain. Could you update this PR to do so and then I'll merge.

@davidism
Copy link
Member
davidism commented Jan 4, 2023

continued in #4935

@davidism davidism closed this Jan 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
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.

3 participants
0