Skip to content

Reject status-code assignment on baked server proxies - #549

Merged
csernazs merged 2 commits into
csernazs:masterfrom
mayankdhingra02:codex/forward-baked-server-attributes
Nov 24, 2026
Merged

csernazs merged 2 commits into
csernazs:masterfrom
mayankdhingra02:codex/forward-baked-server-attributes

Conversation

@mayankdhingra02

@mayankdhingra02 mayankdhingra02 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Assigning no_handler_status_code on a baked proxy can leave it reporting a value that does not match the real server's responses. Expose that setting as an explicit read-only property instead: reads reflect the parent's current value, while assignment and deletion raise AttributeError.

Configure httpserver.no_handler_status_code directly when changing the shared server. Sibling and chained proxies then read the updated setting, including its reset after clear(). This is limited to that one attribute; other assignment behavior remains unchanged.

Validation:

  • Full normal/release and TLS suites pass on Python 3.11.12, 3.12.9, 3.13.3, 3.14.4 and 3.15.2 on macOS. Each normal/release run has 202 passed, 3 skipped and 2 expected failures; TLS has 1 passed.
  • Regression tests reject assignments on direct/chained proxies, preserve the actual HTTP response, follow parent updates/reset and retain other attribute assignment scope. Five cases fail on the previous PR head; all 23 bake tests now pass.
  • make cov, make precommit, make mypy and make doc pass; bake.py has 100% coverage. Optional warning-as-error docs still have the same 61 baseline warnings.
  • Wheel and sdist builds and independently installed HTTP smoke checks pass with exact production source.

Linux and Windows execution remain for CI.

Comment thread pytest_httpserver/bake.py Outdated
def __getattr__(self, name: str) -> Any:
return getattr(self._server, name)

def __setattr__(self, name: str, value: Any) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I see the motivation behind of this change, but I think this change raises some questions:

  1. This will cause the setting of the main httpserver in an "incompatible" way as it will override a value which was set before.

So the code

baked.no_handler_status_code = 404

Won't tell us that it has propagated the setting to the main httpserver and thereby affected all the requests sent to the server.

You can argue that the other expect_request and expect_oneshot_request and others also update the main serve but these are rather extending the list of the expected requests, not overriding them.

  1. I don't like the __setattr__ implementation, I think this could be done with a property specifically with setters and getters (so we turn the attribute to a property first, then we can customize the setter here to update the parent server as well).

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Your example is right: with this PR, setting the value on the baked proxy changes the parent too, so the later request returns 404 rather than 500.

The original problem was that the proxy could report 404 while the actual server still returned 500. The current fix goes too far in the other direction by silently making public assignments affect the shared server.

A small prototype with an explicit getter/setter has the same global effect. Both objects use the same server URL, so changing the implementation to properties alone doesn't settle which object should own the setting.

I agree the blanket __setattr__ should go. For its replacement, would you prefer selected properties documented as shared settings, or read-only properties that reject assignment and require configuring the parent explicitly? Per-proxy response settings would need separate request scoping rather than a setter forwarding to the shared server.

I'll hold the code changes while we settle that contract.

@csernazs csernazs Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think a read-only property would be a good choice here. So the proxy (made by bake()) would reject setting this value as this would have no effect at all. When getting the value it could return the one from the main server.

I'd still keep the current attribute in the scope only.

Comment thread tests/test_bake.py Resolved
@mayankdhingra02 mayankdhingra02 changed the title Forward public server settings through baked proxies Reject status-code assignment on baked server proxies Nov 24, 2026
@csernazs
csernazs merged commit 77beec0 into csernazs:master Nov 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants