Skip to content

Conversation

@Delta17920
Copy link
Contributor

Fixes #576.

This PR refactors the logic for adding new filenames to the file_registry (Filename model).

As suggested by the issue, this logic was previously handled inline in the file_upload view, which is not ideal. This PR moves the logic to a SQLAlchemy event listener.

Changes:

  1. Removed the request.db.add(Filename(filename=filename)) call from warehouse/forklift/legacy.py.
  2. Added an @event.listens_for(File, "after_insert") hook to warehouse/packaging/models.py.

This new hook automatically inserts the File.filename into the file_registry table when a new File is created.

To resolve the SAWarning about modifying a session during a flush, the hook uses a direct connection.execute() operation.


Proof / Test Output:

The existing tests in tests/unit/forklift/test_legacy.py still pass, which confirms the filename logging logic was successfully moved.

image

@Delta17920 Delta17920 requested a review from a team as a code owner October 27, 2025 05:16
Copy link
Member

@di di left a comment

Choose a reason for hiding this comment

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

Thanks! This seems fine to me, I'll let @dstufft review as well though.

@di di requested a review from dstufft October 28, 2025 17:15
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.

Add filenames to registry via trigger/hook/event

2 participants