Skip to content

Fix: schedule_for_cleanup was not called correctly in test_wiki #1369

Open
linglp wants to merge 16 commits into
developfrom
fix-wiki-attachment-cleanup
Open

Fix: schedule_for_cleanup was not called correctly in test_wiki #1369
linglp wants to merge 16 commits into
developfrom
fix-wiki-attachment-cleanup

Conversation

@linglp
Copy link
Copy Markdown
Contributor

@linglp linglp commented Apr 24, 2026

Problem:

I saw this in the Github action run log:

Don't know how to clean: 842124 (type: str)Don't know how to clean: /var/folders/4b/2nnnxx0n2f15srrx6d6ndm7c0000gn/T/tmpmoqiepqs.txt.gz (type: str)Don't know how to clean: https://data.dev.sagebase.org/3705170/65689ca5-6896-4ba1-830d-24c28664fcac/cb646f7f-b828-4ba3-bc78-30edc99bc270?response-content-disposition=attachment%3B%20filename%3D%22preview.txt%22%3B%20filename%2A%3Dutf-8%27%27preview.txt&response-content-type=text%2Fplain&X-Amz-Date=20260424T165655Z&X-Amz-Expires=900&Expires=1777050715&Signature=pq2nTTUMFMCY2bfATv81NBZj8ohyiB-r-noooMYdfdo3xqfAR2nsPY5dRtssYOLOpQ6L0ymkELSqAIXIHg60NYbQEgCAfCGO0VdWgVOcdWewI-6aWq18vGs-h6DJc0t8Z3LH4mhvAFKquZC1dJgylZS5DBchID1rHCl9ULH6qEOu-2lhq0dyzVXMCsU7bgD-ig3g2gYHbbVODTcHwwLytRZvhWJbyNhpk2ZEH5EMNNK3CVEUzfsHXWHvVOyA9k3cbLEAWbKl5844YHf00qtMxiTTuzLvgImmH9G-8n70ftY90GB0SI35Nn9M4YipVSVW~DD6HBC7lHauBef0isu9iA__&Key-Pair-Id=K3YW7HKX09P9M (type: str)Don't know how to clean: 842123 (type: str)Don't know how to clean: /var/folders/4b/2nnnxx0n2f15srrx6d6ndm7c0000gn/T/tmpoo6gu587.txt.gz (type: str)Don't know how to clean: 842122 (type: str)Don't know how to clean: /var/folders/4b/2nnnxx0n2f15srrx6d6ndm7c0000gn/T/tmp2k60nzgx.txt.gz (type: str)Don't know how to clean: https://data.dev.sagebase.org/3705170/e271a957-93bd-4f77-ad3f-b2f3e95931c4/tmp973cxksh.txt.gz?response-content-disposition=attachment%3B%20filename%3D%22tmp973cxksh.txt.gz%22%3B%20filename%2A%3Dutf-8%27%27tmp973cxksh.txt.gz&response-content-type=text%2Fplain&X-Amz-Date=20260424T165642Z&X-Amz-Expires=900&Expires=1777050702&Signature=DWnTcTngKtCO1~GdY7jlF~Zmwv16okQQ2hjaSA-oYk3r9dgDdrDp~vem90E7REjf6VmrZYUu1htEYeB-Y01Sp4T9-5lytb0Cjx5ny2lvY~ZWlbS6X1kk0BY1vZ56-10nfO7ZTNNzdrUp~R6d2SKrB9vT7dJC8N8uYDRzaTmld9k~qLFtZsWEBWKKPVB4yWswxtZQGvNVTATMFxA3pDePR2wMBL3FRKA16IZDHBlAnPssnWEqYelmqfXtuTK-ybM0NVJkx3Pyr0e3nA-~byBi63hbuaG5oK7Ch2JAAAvDtYfKy-tZ9P3e2oW2LfiW~CctWyN~w0sfCtC6le~53MbjpA__&Key-Pair-Id=K3YW7HKX09P9M (type: str)Don't know how to clean: 842121 (type: str)Don't know how to clean: /var/folders/4b/2nnnxx0n2f15srrx6d6ndm7c0000gn/T/tmp973cxksh.txt.gz (type: str)Don't know how to clean: {'list': [{'id': '15915476', 'etag': 'cd2b7f11-fd7e-42fb-bb44-ec5d808a397a', 'createdBy': '3705170', 'createdOn': '2026-04-24T16:56:38.000Z', 'modifiedOn': '2026-04-24T16:56:39.000Z', 'concreteType': 'org.sagebionetworks.repo.model.file.S3FileHandle', 'contentType': 'text/plain', 'contentMd5': 'b73e9cd5b360af5a1581daa468e7e86b', 'fileName': 'tmpc8anir7e.txt.gz', 'storageLocationId': 1, 'contentSize': 54, 'status': 'AVAILABLE', 'bucketName': 'devdata.sagebase.org', 'key': '3705170/57b94ab9-926c-4505-b29f-3956eb019db0/tmpc8anir7e.txt.gz', 'isPreview': False}]} (type: dict)Don't know how to clean: 842119 (type: str)Don't know how to clean: /var/folders/4b/2nnnxx0n2f15srrx6d6ndm7c0000gn/T/tmpc8anir7e.txt.gz (type: str)Don't know how to clean: 842113 (type: str)Don't know how to clean: https://data.dev.sagebase.org/3705170/8989e135-709d-428f-9390-3cf8502c7396/cf02bac7-be5c-4cd4-b06e-490446bd470b?response-content-disposition=attachment%3B%20filename%3D%22preview.txt%22%3B%20filename%2A%3Dutf-8%27%27preview.txt&response-content-type=text%2Fplain&X-Amz-Date=20260424T165625Z&X-Amz-Expires=900&Expires=1777050685&Signature=ZPy949vzQF7I~eliiKolI96JY20gm~chDCYLCTV6cyd8Gxo4FTYVnJ0EAXcOjHiN5C4htK7wH720qVNyy-Ehkjz2lX0CVnYkpgxfKszu5FS2Zk7-sWXJA0xynduMTIIwSPyJl6XNwkOWVD4Mm2ln8bX1jRwUntL45PNEFhEDBmd0EWa7esGt~cCuy12zMM2EHkTr2Nq39lzAu9IeaKjUGsgk9SPaxwacDJrSMXLGGbFiPaPyPQdKjXmX1glOBNdAN9RpteacWVvszRueuB6Q9S-uYh-SzOB2yCdEzkwvrqRJ~nXp3yB5CwjGi71QF9aLPxAM6IRT1wVPy47Z0rA0iA__&Key-Pair-Id=K3YW7HKX09P9M (type: str)Don't know how to clean: 842112 (type: str)Don't know how to clean: 842111 (type: str)Don't know how to clean: https://data.dev.sagebase.org/3705170/f57f976d-e7db-46da-b863-9cc8fe820766/tmpzo077i81.txt.gz?response-content-disposition=attachment%3B%20filename%3D%22tmpzo077i81.txt.gz%22%3B%20filename%2A%3Dutf-8%27%27tmpzo077i81.txt.gz&response-content-type=text%2Fplain&X-Amz-Date=20260424T165554Z&X-Amz-Expires=900&Expires=1777050654&Signature=nE57GNN8CdIBuajtlEwPGbEv3TRLft6iksdBSYmP0~iU2DYNQGII4iNrpJ9PMIBVaddWKvfIbW-rz8RC9TznGSngnHXpL8sZIGYPVKoJDwsy7jb7F2cKd3BN3JYx0ZhNeJLEtpolWXd~KKmqwQwqHYA0AaBLfYe9C1rtyOIulqxF8UJVA-NwkDr4py9uQ14dtQYvRQ9snrobscMnER817752cg2~lwE5gBweXSd~VMRnuZpnaK7ov5AEZkcwrgIhjfEjnWLjBExE-ZaqZCtbyUyGPX9XhLaxFhvsCqV0wnJJWRhTUbuIGn9PJEJQtWGXXhQjOIwmCliqitw68l1~~g__&Key-Pair-Id=K3YW7HKX09P9M (type: str)Don't know how to clean: 842110 (type: str)Don't know how to clean: {'list': [{'id': '15915281', 'etag': '82227281-8cb1-4f90-9098-b0f4d6db2ea3', 'createdBy': '3705170', 'createdOn': '2026-04-24T16:55:50.000Z', 'modifiedOn': '2026-04-24T16:55:50.000Z', 'concreteType': 'org.sagebionetworks.repo.model.file.S3FileHandle', 'contentType': 'text/plain', 'contentMd5': '9dcefc25863c7921fc376fc2cc7618b9', 'fileName': 'tmpnqy28yei.txt.gz', 'storageLocationId': 1, 'contentSize': 73, 'status': 'AVAILABLE', 'bucketName': 'devdata.sagebase.org', 'key': '3705170/6ec6478c-fcfc-49d5-a779-5466600df7d4/tmpnqy28yei.txt.gz', 'isPreview': False}]} (type: dict)Don't know how to clean: 842109 (type: str)

Reason:

schedule_for_cleanup was not called correctly in test_wiki

  • wiki page .id is a numeric string (e.g. "640372"), not a syn-prefixed Synapse ID.

Below can't be cleaned up:

What Why
schedule_for_cleanup(attachment_handles) dict — no cleanup method
schedule_for_cleanup(attachment_url) / schedule_for_cleanup(markdown_url) / schedule_for_cleanup(preview_url) Pre-signed URL strings — not local paths, not Synapse entities
schedule_for_cleanup(history) list[WikiHistorySnapshot] — no delete_async
schedule_for_cleanup(headers) list[WikiHeader] — no delete_async
schedule_for_cleanup(order_hint) / updated_order_hint / retrieved_order_hint WikiOrderHint — no delete_async

Solution:

Updated wiki async integration tests to only schedule cleanup for actual deletable entities or local filesystem paths. Specifically:

  • Replaced wiki cleanup calls from raw id strings to wiki objects.
  • Removed cleanup calls for non-cleanable values (URLs, handles dicts, history/header lists, WikiOrderHint objects
  • Also made sure that all the tests consistently use self.schedule_for_cleanup instead of passing schedule_for_cleanup as a parameter
    `

download_location=download_dir,
synapse_client=self.syn,
)
schedule_for_cleanup(downloaded_path)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need this because temporary directory is already being cleaned up above.

@linglp linglp marked this pull request as ready for review May 14, 2026 15:38
@linglp linglp requested a review from a team as a code owner May 14, 2026 15:38
Copilot AI review requested due to automatic review settings May 14, 2026 15:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the async Wiki integration tests to call schedule_for_cleanup with values that the integration-test cleanup harness can actually delete, eliminating noisy “Don’t know how to clean …” messages (notably from passing numeric wiki IDs and other non-cleanable values).

Changes:

  • Replaced wiki cleanup calls from raw numeric wiki ID strings to WikiPage objects (so _cleanup can call delete_async).
  • Removed cleanup scheduling for non-cleanable return values (pre-signed URL strings, handle dicts, header/history lists, order-hint objects).
  • Standardized tests to use self.schedule_for_cleanup (via the init autouse fixture) instead of threading schedule_for_cleanup through many test signatures.
Comments suppressed due to low confidence (3)

tests/integration/synapseclient/models/async/test_wiki_async.py:309

  • This test creates a >8MiB temp file via make_bogus_uuid_file() and writes to it, but the file path is no longer scheduled for cleanup. That can leave large files on disk after local runs; schedule filename for cleanup once the upload is complete.
        # Create a temporary file for attachment with > 8 MiB
        filename = utils.make_bogus_uuid_file()
        with open(filename, "wb") as f:
            f.write(b"\0" * (9 * 1024 * 1024))

tests/integration/synapseclient/models/async/test_wiki_async.py:349

  • This fixture renames the temp file to gz_filename and writes it, but the local gz file is not scheduled for cleanup anymore. Since make_bogus_uuid_file() uses delete=False, consider scheduling gz_filename (and/or removing filename if it still exists) for cleanup to avoid leaking temp files.
        # Create a gzipped file
        filename = utils.make_bogus_uuid_file()
        # Rename to add .gz extension
        gz_filename = filename + ".gz"
        os.rename(filename, gz_filename)
        with gzip.open(gz_filename, "wt") as f:
            f.write("hello world\n")

tests/integration/synapseclient/models/async/test_wiki_async.py:583

  • This fixture creates and writes md_gz_filename via make_bogus_uuid_file()/delete=False, but no longer schedules that local file for cleanup. Either schedule md_gz_filename for cleanup or remove this unused temp file creation to prevent leaking files during integration test runs.
        filename = utils.make_bogus_uuid_file()
        # Rename to add .md.gz extension
        md_gz_filename = filename.replace(".txt", ".md.gz")
        os.rename(filename, md_gz_filename)
        with gzip.open(md_gz_filename, "wt") as f:
            f.write("# Test Wiki\n\nThis is test content.")


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/integration/synapseclient/models/async/test_wiki_async.py
retrieved_wiki = await WikiPage(
owner_id=root_wiki.owner_id, id=root_wiki.id
).get_async(synapse_client=self.syn)
schedule_for_cleanup(retrieved_wiki.id)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here, even for deleting wiki, the code should be:

schedule_for_cleanup(retrieved_wiki)

But the wiki shouldn't be deleted because wiki_page_fixture is a class level fixture. If we delete it here, then this would potentially affect other tests

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread tests/integration/synapseclient/models/async/test_wiki_async.py
Comment thread tests/integration/synapseclient/models/async/test_wiki_async.py Outdated
@andrewelamb
Copy link
Copy Markdown
Contributor

I had one question, but overall LGTM!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

schedule_for_cleanup(retrieved_order_hint)
assert retrieved_order_hint.id_list == header_ids
assert len(retrieved_order_hint.id_list) >= 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No need to clean up wiki pages here because the project will be cleaned up anyway:

    @pytest.fixture(scope="class")
    async def wiki_page_fixture(
        self, syn: Synapse, schedule_for_cleanup: Callable[..., None]
    ) -> WikiPage:
        """Create a root wiki page fixture shared across tests in this class."""
        project = Project(name=f"Test Wiki Project_" + str(uuid.uuid4()))
        project = await project.store_async(synapse_client=syn)
        schedule_for_cleanup(project.id)
        wiki_title = f"Root Wiki Page {str(uuid.uuid4())}"
        wiki_markdown = "# Root Wiki Page\n\nThis is a root wiki page."
        wiki_page = WikiPage(
            owner_id=project.id,
            title=wiki_title,
            markdown=wiki_markdown,
        )
        root_wiki = await wiki_page.store_async(synapse_client=syn)
        return root_wiki

@linglp linglp requested review from BryanFauble and danlu1 May 14, 2026 16:10
)
wiki_page = await wiki_page.store_async(synapse_client=self.syn)
schedule_for_cleanup(wiki_page.id)
self.schedule_for_cleanup(wiki_page)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since wiki is not an entity, would this also fail to cleanup?

Copy link
Copy Markdown
Contributor Author

@linglp linglp May 18, 2026

Choose a reason for hiding this comment

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

Hi @BryanFauble ! I later realized that wiki page was handled explicitly by the code here. I will remove WikiOrderHint, WikiHistorySnapshot, and WikiHeader from conftest because they don't have delete function and can't be deleted that way

download_location=download_dir,
synapse_client=self.syn,
)
schedule_for_cleanup(downloaded_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could probably be kept to cleanup the file.

)
sub_wiki = await wiki_page.store_async(synapse_client=syn)
schedule_for_cleanup(sub_wiki.id)
schedule_for_cleanup(sub_wiki)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread tests/integration/synapseclient/models/async/test_wiki_async.py
)
sub_wiki = await wiki_page.store_async(synapse_client=syn)
schedule_for_cleanup(sub_wiki.id)
schedule_for_cleanup(sub_wiki)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

)
sub_wiki = await wiki_page.store_async(synapse_client=syn)
schedule_for_cleanup(sub_wiki.id)
schedule_for_cleanup(sub_wiki)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

owner_id=root_wiki.owner_id, id=updated_wiki.id, title="Version 2"
).store_async(synapse_client=syn)
schedule_for_cleanup(updated_wiki.id)
schedule_for_cleanup(updated_wiki)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@BryanFauble BryanFauble left a comment

Choose a reason for hiding this comment

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

A few things to patch up, otherwise LGTM!

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