prefect icon indicating copy to clipboard operation
prefect copied to clipboard

2.x variable return value fix

Open Samreay opened this issue 1 year ago • 1 comments

Checklist

  • [x] This pull request references https://github.com/PrefectHQ/prefect/issues/15061

Samreay avatar Aug 26 '24 01:08 Samreay

Thanks for the PR @Samreay! It looks like the tests didn't run for some reason. I suspect some of the tests in tests/test_variables.py will need to be updated. Could you update those tests to make sure they pass (and if they do, push another commit to try and get CI to run)?

desertaxle avatar Aug 26 '24 14:08 desertaxle

Variable tests appear to be failing which makes me think there's something I'm missing here 🧐

cicdw avatar Aug 29 '24 17:08 cicdw

@cicdw this is a fun one. There's the class in prefect.variables.Variables and I was assuming that the get method when using Variable.get would return an instance of that class. It doesn't - it returns an instance of prefect.client.schemas.objects.Variable, and so the isinstance check is failing.

I suppose this means my type hints are technically wrong, but still functional due to duck typing.

I'll swap the code to doing a string check and hasattr so Im not importing a second Variable class and making life hell for people down the road trying to figure out which class they want. (I dont understand the different between the two - is one just used for a serialisation layer?)

Samreay avatar Sep 02 '24 02:09 Samreay

@Samreay wow that's rough, I'm sorry about that! Yea the schema object is just serialization layer, so I think you can update get to return a class instance of prefect.variables.Variable, the schema objects really don't need to be exposed directly to users

cicdw avatar Sep 03 '24 00:09 cicdw

@cicdw I have now updated the get method so that it returns the expected class. Hopefully this all looks good now :)

Samreay avatar Sep 03 '24 02:09 Samreay