Skip to content

Conversation

@allison-truhlar
Copy link
Collaborator

This PR was motivated by encountering these errors for test_config_template.py:

  ERROR tests/test_config_template.py::test_server_launches_with_template - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: file_share_paths                                                                                                                           
  ERROR tests/test_config_template.py::test_view_home_directory_no_error - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: file_share_paths                                                                                                                            
  ERROR tests/test_config_template.py::test_profile_endpoint_no_error - sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: file_share_paths

I'm not 100% sure why these tests started failing locally, why they still pass on GH actions, and why this fix now allows them to pass locally. After much back-and-forth with Claude, I still do not have a satisfactory answer, but I have decided to move on for now to get back to more pressing work. The best explanation I can offer is that somehow (but only locally and starting only recently), the test was referring to two different engines that each had their own database.

Old test flow:

  1. Test code creates engine using create_engine() directly → Engine 1
    - This engine has its own in-memory database
    - Test creates tables and data in Engine 1's database
  2. App code calls create_app() → internally uses _get_engine() → Engine 2 (cached)
    - This is a completely separate engine instance
    - For sqlite:///:memory:, this means a separate in-memory database
    - Engine 2's database is empty - no tables, no data
  3. Tests run → app endpoints use Engine 2 → "no such table" error

New test code:
db_module._get_engine(template_settings.db_url) # Gets/creates the cached engine
db_module.Base.metadata.create_all(engine) # Creates tables in the cached engine
app = create_app(template_settings) # Uses the same cached engine by calling _get_engine internally

- the previous way was initializing separate dbs in memory, resulting in an error that the table file_share_paths didn't exist
Copy link
Member

@neomorphic neomorphic left a comment

Choose a reason for hiding this comment

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

It looks like this fixes the issue, but in a suboptimal way. We should revisit this the next time we work on these tests. But it is not vitally important to get this correct at this time, so we should proceed with this fix.

@allison-truhlar
Copy link
Collaborator Author

@neomorphic Were you able to gain any further insight as to why this fix works?

@allison-truhlar allison-truhlar merged commit bd1b51f into main Jan 15, 2026
7 checks passed
@allison-truhlar allison-truhlar deleted the fix-config-template-tests branch January 15, 2026 14:35
@krokicki
Copy link
Member

This works but it uses private database APIs which couples the internals of the database module to the tests.

As an alternative, test_endpoints.py uses a file-based database to get around this issue of different in-memory databases, which might be simpler and easier to understand.

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.

4 participants