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

Upgrade cel-python to 0.2.0 #252

Merged
merged 14 commits into from
Feb 25, 2025
Merged

Conversation

stefanvanburen
Copy link
Member

@stefanvanburen
Copy link
Member Author

@jchadwick-buf it would appear that enabling typing in celpy hit off a bunch of type errors that look relatively valid to me — any chance you could take a peek and confirm it looks like something we should fix, rather than just disabling typing for the celpy module?

@jchadwick-buf
Copy link
Member

I'm weary of doing this, because I don't think cloud-custodian/cel-python#73 is fixed. We will have to carefully port our monkey patching in cel_field_presence.py.

@stefanvanburen
Copy link
Member Author

@jchadwick-buf hm, that may be an issue but I'm not sure it's relevant to the failures here - I'm mostly talking about the type mismatches that we seemingly have, e.g. in extra_func.py we have some failures related to passing a celpy.BoolType instead of a bool. Are those related? Are those codepaths actually flexed (maybe by conformance)?

@jchadwick-buf
Copy link
Member

jchadwick-buf commented Feb 14, 2025

Yeah, I'm sure it's not related to the errors, but at the very least we can't unpin the cel-python dependency even if we update it. The code paths with errors are indeed exercised (by conformance), so I'm guessing the API or types have broken on us as of cel-python 0.2.0.

The rest is just string_format, which does not appear to be flexed by
conformance.
@stefanvanburen
Copy link
Member Author

@jchadwick-buf I took a pass at updating some of the types in 9e83b45. The only remaining errors are in StringFormat, which AFAICT is not flexed by the conformance tests. (Should it be?)

at the very least we can't unpin the cel-python dependency even if we update it

I guess I'm confused — the tests here, including the conformance tests, all pass — the only thing that doesn't work are the type-hints, which are only new due to celpy enabling them. I think the latest commit is correct for the types I changed, and now I'd just like to determine if we want to fix the remaining typing issues with StringFormat (which, to be clear, I think are real runtime issues because nothing I can see is running that code).

Isn't your monkey-patching in cel_field_presence.py flexed by the conformance tests? (Sorry if I'm being dense about all of this, trying to figure out if I'm missing something 😄.)

@jchadwick-buf
Copy link
Member

My concern is that if our dependency states we can take any version of cel-python, then presumably when someone depends on us, they can get a newer version of cel-python that we haven't run the conformance tests against.

@stefanvanburen
Copy link
Member Author

My concern is that if our dependency states we can take any version of cel-python, then presumably when someone depends on us, they can get a newer version of cel-python that we haven't run the conformance tests against.

Sorry I should have been clear — that's what this PR is doing: https://github.com/bufbuild/protovalidate-python/pull/252/files#diff-a86c67a0a29ed0e95909b9b7c420140f302d17399ee6dcce4e1a51a14d27fd51R26. (I had to remove the direct pin on 0.1.5 to upgrade at all; I've re-pinned to ==0.2.* to make that clear)

@jchadwick-buf
Copy link
Member

Interesting. Sorry, I didn't realize it couldn't just be updated by changing the version number in the Pipfile.

@stefanvanburen
Copy link
Member Author

yeah, bumped the version and then re-locked the Pipfile.lock.

Thoughts on fixing StringFormat? It looks like it must be available in the CEL env and I'm assuming it's tested in our other impls, but doesn't seem to be tested here AFAICS?

@jchadwick-buf
Copy link
Member

String formatting is used extensively in protovalidate, e.g. it is used by many of the standard rules. (For example, look at this.) It definitely will get exercised by the conformance test.

It would seem that the conformance tests do not flex the formatting that
we appear to support here, or just don't check for it?
@stefanvanburen stefanvanburen force-pushed the svanburen/upgrade-cel-python branch from f9c905c to 3071c6d Compare February 18, 2025 15:10
@stefanvanburen
Copy link
Member Author

String formatting is used extensively in protovalidate, e.g. it is used by many of the standard rules. (For example, look at this.) It definitely will get exercised by the conformance test.

yeah, interesting — I think maybe those tests just aren't flexing whatever we're providing as a format implementation, as simplifying the implementation of format down to effectively an identity function still passes the conformance tests.

@stefanvanburen
Copy link
Member Author

ah, I think I might see what's happening: we aren't passing --strict_message to the conformance suite. Going to see how this works with that flag turned on.

Comment on lines -47 to +52
return celpy.native_to_cel(celpy.new_error("format() requires a string as the first argument"))
return celpy.CELEvalError("format() requires a string as the first argument")
if not isinstance(args, celtypes.ListType):
return celpy.native_to_cel(celpy.new_error("format() requires a list as the second argument"))
return celpy.CELEvalError("format() requires a list as the second argument")
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't see a native_to_cel or new_error anywhere in cel-python — while I doubt we ever hit these cases (more of an assert?), figured it made sense to update them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unused code AFAICT.

Copy link
Member

@jchadwick-buf jchadwick-buf Feb 25, 2025

Choose a reason for hiding this comment

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

Although this is technically unused (after removing the legacy field path field), we actually plan on exposing it as a public API.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, ok. want me to add it back here, or are you going to add it in some other form pre-1.0?

Copy link
Member

Choose a reason for hiding this comment

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

no big deal, it's always in the version control history

@stefanvanburen stefanvanburen marked this pull request as ready for review February 19, 2025 14:44
@stefanvanburen
Copy link
Member Author

@jchadwick-buf I think this is ready for a look when you've got review cycles, but no rush.

@stefanvanburen stefanvanburen merged commit 85b2b9f into main Feb 25, 2025
12 checks passed
@stefanvanburen stefanvanburen deleted the svanburen/upgrade-cel-python branch February 25, 2025 14:59
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.

2 participants