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

bug(file): fix for #95 #96

Closed
wants to merge 3 commits into from

Conversation

dzmitry-lahoda
Copy link

No description provided.

@mlech-reef
Copy link
Collaborator

@dzmitry-lahoda thank you for the fix. Looks like old file versions created before content_md5 field was added do not have it. I believe it was before the first version of this provider. Have you imported some old file into the terraform state?

Regarding the nix flake, I understand you use it to have preinstalled python toolset, however it is not something we want to maintain, and it is not compatible with the rest of this provider, e.g. python-bindings/requirements-dev.txt. I kindly ask you to remove it from this PR. You can add it to the gitignore if you want to use it for yourself.

Please also add an appropriate entry to the CHANGELOG.md, otherwise the CI will fail.

Best regards,
Maciej Lech

@mlech-reef mlech-reef linked an issue Feb 7, 2025 that may be closed by this pull request
@mlech-reef mlech-reef self-requested a review February 7, 2025 17:02
@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Feb 7, 2025

these files are not old 100%.

i just created file version resource two days ago with whatever provider version published in registry at that time.

all was created 2 days ago. i did not imported anything. resource creation fails with error.

https://github.com/n1xyz/n1.nix/blob/dz/1/infra/base/.terraform.lock.hcl

@mlech-reef
Copy link
Collaborator

these files are not old 100%.

i just created file version resource two days ago with whatever provider version published in registry at that time.

Ok, as I see, according to the B2 API docs these fields are optional, so having them optional here make perfect sense. Thanks

@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed `allowed_operations` stability issue
* Use macos-14 for ARM as macos-13-large is Intel
* Clarified the purpose of the `endpoint`/`B2_ENDPOINT` configuration value
* Marked md5 and sha1 hashes as optional
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put it under Unreleased and not 0.9.0:

## [Unreleased]

### Fixed
* Marked md5 and sha1 hashes as optional

@mlech-reef
Copy link
Collaborator

I have looked more deeply into this problem, and unfortunately:

  1. your solution doesn't work
  2. setting Optional and Computed has another undesired outcome

Ad. 1.
The reason it doesn't work is how we handle response from the python SDK. We require every field to be returned.

Ad. 2.
The undesired behavior is because of:

// Computed indicates whether the provider may return its own value for
// this attribute or not. Computed cannot be used with Required. If
// Required and Optional are both false, the attribute will be considered
// "read only" for the practitioner, with only the provider able to set
// its value.

Computed bool

It means, with Optional, terraforms allows setting content_md5, e.g.:

resource "b2_bucket_file_version" "test" {
  bucket_id    = b2_bucket.test.id
  file_name    = "file.txt"
  source       = "file.txt"
  content_type = "octet/stream"
  content_md5  = "test"
}

Without that, it throws Error: Value for unconfigurable attribute which is the desired behavior.


I was able to solve the problem differently. I will create a new PR.

BR/ Maciej Lech

@mlech-reef
Copy link
Collaborator

Also, it looks like for the large files, sha1 is set to "none" string and md5 is None and excluded from the SDK response.

@mlech-reef
Copy link
Collaborator

A new PR #97

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.

error getting content_md5 on big files
2 participants