Skip to content

Fix AttributeError when importing eyepieces from DeepskyLog#529

Open
brickbots wants to merge 2 commits into
mainfrom
fix/dsl-eyepiece-import-crash
Open

Fix AttributeError when importing eyepieces from DeepskyLog#529
brickbots wants to merge 2 commits into
mainfrom
fix/dsl-eyepiece-import-crash

Conversation

@brickbots

@brickbots brickbots commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

Importing equipment from DeepskyLog on the web interface crashes with an "Internal Server Error" as soon as the import contains a new eyepiece. This is a v2.5.1 → v2.6.0 regression introduced by the Flask migration (#331), which changed the eyepiece-add call from

cfg.equipment.add_eyepiece(new_eyepiece)

to

cfg.equipment.eyepieces.add_eyepiece(new_eyepiece)

Equipment.eyepieces is a plain List[Eyepiece] with no add_eyepiece method, so the first new eyepiece raises AttributeError. Since cfg.save_equipment() comes after the import loop, nothing gets saved — telescopes already collected in the same request are lost too.

This PR restores the pre-migration call on Equipment itself (equipment.py:87), which appends the eyepiece and keeps the list sorted by focal length. The manual add-eyepiece route was unaffected (it already calls the correct method at server.py:736).

Regression tests

tests/test_server_dsl_import.py drives the real /equipment/import_from_deepskylog route through Flask's test client, with pydeepskylog and config.Config mocked out and a real Equipment instance so the plain-list bug reproduces:

  • test_import_adds_new_eyepieces — new eyepieces are added (sorted by focal length, HTML entities decoded) and the config is saved. With the bad call reintroduced, this fails with AttributeError: 'list' object has no attribute 'add_eyepiece' — verified.
  • test_import_skips_existing_eyepiece — an eyepiece already in the config is not duplicated.

Test plan

  • New regression tests pass (and fail on the un-fixed code)
  • pytest -m "unit or smoke" passes (785 passed)
  • ruff check / ruff format --check pass

🤖 Generated with Claude Code

The Flask migration (#331) changed the DeepskyLog eyepiece import to
call add_eyepiece() on Equipment.eyepieces, which is a plain list with
no such method. The first new eyepiece raised AttributeError, surfacing
as "Internal Server Error", and nothing was saved since save_equipment()
comes after the loop. Restore the pre-migration call on Equipment
itself, which also keeps the eyepiece list sorted by focal length.

Regression: v2.5.1 -> v2.6.0 (9e96d22)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mrosseel

Copy link
Copy Markdown
Collaborator

Seems like this cold use a unit test/integration test. Are these run regularly btw?

Drive /equipment/import_from_deepskylog through Flask's test client with
pydeepskylog and config mocked, using a real Equipment instance so the
plain-list AttributeError from the Flask migration would reproduce.
Covers: new eyepieces added (sorted, entities decoded, config saved) and
duplicates skipped. Verified the first test fails with AttributeError
when the bad call is reintroduced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@brickbots

Copy link
Copy Markdown
Owner Author

Yes indeed! I'll make sure to add a test. Web interface tests don't run as part of the CI/CD, so it's something we'll need to do more of manually as part of a release 👍

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