fix(1011): default molimg height/width when not supplied - #1012
Open
claude-im wants to merge 1 commit into
Open
Conversation
MolImageSerializer.get_mol_image sized the image from the request's height/width query parameters but guarded that lookup with a bare `if params:`, which is true whenever *any* query parameter is present. A request that filters or paginates without asking for a size - e.g. /api/molimg/?target=1 - hit the parameter lookup with no height, raising MultiValueDictKeyError and surfacing as a 500 on /api/molimg/. Read each dimension through a small _int_param() helper so it falls back to its default independently, and promote the 125x125 defaults to named class attributes. A supplied but unparseable value still raises, as before - that is a separate concern. Add a regression test that reproduces the production error (a filtering parameter with no size) and covers the no-parameter, explicit-size, one-dimension-only and float-valued cases. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1011.
Problem
/api/molimg/returns 500 in production.MolImageSerializer.get_mol_imagesized the image from the request'sheight/widthquery parameters, but guarded that lookup with a bareif params::MolImgFilteracceptstarget,cmpd,smilesandsite_observation_groups, so/api/molimg/?target=1— or plain?page=2pagination — makesparamstruthy with no size in it, and the lookup raisesMultiValueDictKeyError: 'height'. The all-or-nothing guard only ever worked for requests that supplied both dimensions or no parameters at all.Fix
Each dimension is read through a small module-level
_int_param()helper and defaults independently, so filtering and pagination parameters no longer affect sizing:The 125×125 defaults become named class attributes rather than repeated literals. Behaviour is otherwise unchanged: values are still read via
float()so decimal strings are accepted and truncated.No API contract change — responses that worked before are byte-identical.
Out of scope (noted, not fixed)
A supplied but unparseable size (
?height=abc) still raisesValueError→ 500. That is pre-existing behaviour and a different defect; properly it should be a 400 from request validation. Happy to file it separately if you'd like it dealt with.Testing
New regression test
viewer/tests/test_molimg_serialization.py, written first (TDD) — it reproduced the exact productionMultiValueDictKeyErrorbefore the fix. It covers:height/width→ honoured;Full suite: 350 passed, 1 skipped.
pre-commit(isort/black/mypy/pylint) clean.🤖 Generated with Claude Code