-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Upgrade Azure Blob Storage SDK to v12 #2573
base: master
Are you sure you want to change the base?
Conversation
There's an admin test that is failing in CI that isn't failing locally, so I'm going to put some debugging in in the next commits to try to figure out what's happening. |
FYI, it is failing for me locally too 👀 Not that it helps much ... but I can possibly investigate a bit myself and see if I find anything. |
If it helps:
|
Thanks! Might be a statefulness thing, I'll start a fresh env. |
...Wouldn't it be better to include actual information in that The check would work the same, and the error could be logged properly before redirect (...as it probably should be, anyway.) |
@samuelhwilliams It was an error due to the tests using an older Azure storage emulator, I've updated them to the official Microsoft hosted emulator now, and they're passing fine. |
@@ -0,0 +1,14 @@ | |||
// For format details, see https://aka.ms/devcontainer.json. | |||
{ | |||
"name": "flask-admin (Python + Azurite)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, I could add Postgres and Mongo to this dev container too, to have a single container that can run all the tests. It should be fairly easy given tests.yaml has the services setup, just copying that to docker-compose.yaml.
from azure.storage.blob import BlobServiceClient | ||
from azure.storage.blob import generate_blob_sas | ||
except ImportError as e: | ||
raise Exception( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the handling of the importerror to make mypy happier. I looked at other optional modules and they all seemed to handle importerrors a bit differently. I found one that did it this way. This seems fine since you should import the module unless you're using it.
Hm, it appears I still don't have an approach for handling unimportable Azure modules that makes mypy happy. Let me know if you have any thoughts about the best practice for importing extra modules in tests (and skipping tests if they don't exist). I'll take another look Monday otherwise. |
I don't think we need to support tests running without azure installed - I'd probably be fine with you removing the try/except around that test import. |
Okay, I've made it so that the tests assume you've got azure-blob-storage installed. I've also made the tests devcontainer bring in Postgres and Mongo too, so I was able to get all the tests passing in my dev container environment, without additional setup. |
self._container_name = container_name | ||
self._connection_string = connection_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the changes I made on the s3 admin side when bringing it up to date was to have __init__
take a client instance rather than parameters that get passed the client.
Do you think we should do something similar here and accept an instance of BlobServiceClient
, or is it still fine to just use the connection string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think thats nice, as I personally don't typically use connection strings (this was my first time using from_connection_string), so that gives developers more flexibility as to how they connect. I can make that change. That'd be breaking, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be, but this is scheduled to go out for the v2 release where we're making a bunch of breaking changes, so I'm ok with it.
If you'd be happy to, feel free :) 🙏
I'm not sure the |
I also think I'm getting one error in the devcontainer that feels odd: But clearly it passes in CI, so... |
@samuelhwilliams I put the hstore setup in the postAttachCommand, but that doesnt' run until really late in the process, so it's possible you ran the tests before that had been run. I can make it more robust by instead bringing in a Dockerfile for the postgis and putting the CREATE EXTENSIOn in there. @samuelhwilliams Do you get that error when there are no changes locally? Sometimes errors happen with partially aborted tests due to dangling changes to dummy files. |
Apologies - both of these problems were on my end, my checkout of your latest changes failed so I still had an old version of the PR cached. After resetting that, unfortunately I get a new error that looks unrelated - not able to install But I think, yeah, neither of these things are strictly this PR's problem... |
@samuelhwilliams I ran into both install issues. I've been commenting out numpy and manually installing Flask==3.0.0. I wasn't sure whether to tackle those in the PR or not. |
@samuelhwilliams I'll check on the download error, that sounds like a flow I didn't do. (And perhaps isnt covered by tests, given they're passing). And add a link. |
Ah ok that's reassuring for me at least. I think it's fine to leave it for a separate PR; I'll raise an issue on it...
Brill, thanks! |
The error with download_file looks like this Azurite issue: |
…stead of SAS, add prod config to example
Update:
|
FYI: there are no type annotations for AzureFileAdmin and S3FileAdmin currently. When we add them in, we get a mypy error about "multiple values for keyword storage". I think it's confused by the args/kwargs around it. So I have left off type annotations on AzureFileAdmin for now, though I added them to the storage class in a few places. |
Fixes #2566
This PR upgrades the azure-storage-blob SDK from v2 to v12, which involved a lot of interface changes. I followed the migration guide @ https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/storage/azure-storage-blob/migration_guide.md and was able to get all the previous functionality working, at least according to the tests.
For ease of testing, I added a simple example app and a devcontainer.azure.json which brings in the Azurite local emulator. That means you can open this repo inside a Codespace or Dev Container with that configuration, and Azure Blob Storage will be running for you.