Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dont raise FileNotFoundError from close() on tmpfile rename #550

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

jjinno
Copy link
Contributor

@jjinno jjinno commented Mar 13, 2024

Description

Allow FileNotFoundError to be ignored on close() to compensate for file already being renamed

Motivation and Context

There appear to be some conditions by which the self._tmp_filename file has already been renamed/moved to self.filename prior to (or racing with) the calling of close().

In this case FileNotFoundError will be thrown, causing the Terraform to fail. But without changing anything, a subsequent run of the Terraform will succeed because the ZIP file already exists. (aka: it was created correctly on the first pass)

Breaking Changes

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@jjinno jjinno changed the title fix: dont fail close() on tmpfile rename Fix: dont fail close() on tmpfile rename Mar 13, 2024
@jjinno jjinno changed the title Fix: dont fail close() on tmpfile rename fix: Dont fail close() on tmpfile rename Mar 13, 2024
@jjinno jjinno changed the title fix: Dont fail close() on tmpfile rename fix: Dont raise FileNotFoundError from close() on tmpfile rename Mar 13, 2024
package.py Outdated Show resolved Hide resolved
package.py Show resolved Hide resolved
jjinno and others added 2 commits March 18, 2024 20:05
check for file existence before fail-check

Co-authored-by: Patrick Decat <pdecat@gmail.com>
package.py Outdated Show resolved Hide resolved
@jjinno jjinno requested a review from pdecat March 29, 2024 00:18
@edrjnjdeuh73
Copy link

Thx. Ad astra!

Copy link
Contributor

@pdecat pdecat left a comment

Choose a reason for hiding this comment

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

LGTM!

@antonbabenko antonbabenko merged commit 58ba987 into terraform-aws-modules:master Mar 29, 2024
29 checks passed
antonbabenko pushed a commit that referenced this pull request Mar 29, 2024
## [7.2.4](v7.2.3...v7.2.4) (2024-03-29)

### Bug Fixes

* Dont raise FileNotFoundError from close() on tmpfile rename ([#550](#550)) ([58ba987](58ba987))
@antonbabenko
Copy link
Member

This PR is included in version 7.2.4 🎉

@lociko
Copy link
Contributor

lociko commented Mar 29, 2024

It looks like something wrong:

if not os.exists(self._tmp_filename):
            return

It will raise an exception!!!
The correct version is: os.path.exists

@lociko
Copy link
Contributor

lociko commented Mar 29, 2024

@pdecat
Copy link
Contributor

pdecat commented Mar 29, 2024

I'm going to add python lint checks to CI to catch this sort of mistakes.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants