Handle IMAP attachment filename collisions#69468
Closed
09Catho wants to merge 1 commit into
Closed
Conversation
Signed-off-by: 09Catho <ashketchume45@gmail.com>
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the IMAP provider’s ImapHook.download_mail_attachments behavior to make attachment filename collision handling configurable, addressing data loss when multiple attachments share the same filename.
Changes:
- Adds an
overwrite_fileoption toImapHook.download_mail_attachments(defaulting to the current overwrite behavior). - When
overwrite_file=False, preserves all attachments by writing suffixed filenames (e.g.report_1.csv,archive.tar_1.gz) using an atomic create ("xb") loop. - Adds unit regression coverage for both overwrite and non-overwrite modes, including filenames with no extension and multiple extensions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| providers/imap/src/airflow/providers/imap/hooks/imap.py | Adds overwrite_file option and implements suffix-based collision handling when overwrite is disabled. |
| providers/imap/tests/unit/imap/hooks/test_imap.py | Adds regression tests validating collision behavior for both overwrite and non-overwrite modes. |
Contributor
|
Fixed in #68838 |
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.
Summary
overwrite_fileoption toImapHook.download_mail_attachments, defaulting to the existing overwrite behavioroverwrite_file=Falseby writing numeric suffixed copies such asreport_1.csvFixes #65870
Tests
python -m ruff check providers\imap\src\airflow\providers\imap\hooks\imap.py providers\imap\tests\unit\imap\hooks\test_imap.pypython -m ruff format --check providers\imap\src\airflow\providers\imap\hooks\imap.py providers\imap\tests\unit\imap\hooks\test_imap.pygit diff --check_create_filepreserving duplicate filenames and overwriting existing filesI also attempted the focused pytest target with Airflow's managed environment:
uv run python -m pytest providers\imap\tests\unit\imap\hooks\test_imap.py -qThat environment setup failed on Windows before running tests because
apache-airflow[all]pullsapache-airflow-core[memray], andmemray==1.19.3reportsmemray does not support this platform (win32).