This fixes a bug introduced in #36: when generating images with drizzle and a magnification cut, the size of all future generated images doubles (along both axes) whenever one image fails the magnification cut.
This is because draw_drizzle monkeys around with ConfigHandler's stateful attributes, but it is terminated by a custom exception before it cleans up the evidence of its dastardly work.
This PR fixes the bug by catching the exception in _draw_image_drizzle, cleaning up the affected properties, then reraising it.
In the future, we might want to
Add a unit test to reproduce this, to avoid regressions
Consider cleaner solution, e.g. refactoring _draw_image_drizzle to use a try-finally block, or passing numpix etc. via function arguments rather the ConfigHandler state.
Coverage increased (+0.01%) to 95.056% when pulling ee3c045b5eb6f621a1dd36270288a483408dd750 on fix_mag_cut into 2edd7f418a63273d5b2fcc75819e811bceb1f149 on main.
This a great catch, and the change looks good. Long term I agree we want to refactor how the drizzling is being done right now / how the config is treated.
This fixes a bug introduced in #36: when generating images with drizzle and a magnification cut, the size of all future generated images doubles (along both axes) whenever one image fails the magnification cut.
This is because
draw_drizzle
monkeys around withConfigHandler
's stateful attributes, but it is terminated by a custom exception before it cleans up the evidence of its dastardly work.This PR fixes the bug by catching the exception in _draw_image_drizzle, cleaning up the affected properties, then reraising it.
In the future, we might want to