Skip to content

Conversation

@srikrsna-buf
Copy link
Member

Today celType is only used in the type CEL function and error messages. It is also exported. If an any were to be passed to celType it will report it as a google.protobuf.Any which is different from what type returns. This change modifies celType to account for Any.

/**
* Returns true if v satisfies type t.
*
* For lists and maps
Copy link
Member

Choose a reason for hiding this comment

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

Need to complete sentence or drop the line :)

I would prefer that we explain how DYN behaves here, even if "satisfies" gives an indication.

Comment on lines +361 to +364
if (typeName === ValueSchema.typeName) {
const value = anyUnpack(v.message, ValueSchema);
return value ? valueToType(value) : CelScalar.NULL;
}
Copy link
Member

Choose a reason for hiding this comment

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

For a google.protobuf.Any containing a message other than google.protobuf.Value, celTypeOfMessage will still yield an object type google.protobuf.Any. Shouldn't we unwrap as well? We'll need an overload to function objectType that doesn't require a DescMessage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep missed that in a refactor, done in 46d561e

function celTypeOfMessage(v: ReflectMessage): CelType {
let typeName = v.desc.typeName;
if (isReflectMessageAny(v)) {
typeName = typeUrlToName(v.message.typeUrl);
Copy link
Member

Choose a reason for hiding this comment

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

We'll error for an empty google.protobuf.Any.

I am not sure what the correct behavior is - this isn't explicitly specified.

For now, let's add a test to capture the behavior. We should have at least a few tests for function celType, including the behavior for Any we're fixing here and including the edge case behavior for an empty Any.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't it the same as unwrapping an Any? This is consistent with other functions like equal

Copy link
Member

Choose a reason for hiding this comment

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

The CEL spec says:

All google.protobuf.Any typed fields are unpacked before comparison, unless the type_url cannot be resolved, in which case the comparison falls back to byte equality.

equals from @bufbuild/protobuf follows that, and considers two empty Any messages equal.
bufbuild/protobuf-es#1338

@srikrsna-buf srikrsna-buf merged commit e664f0d into main Jan 15, 2026
11 checks passed
@srikrsna-buf srikrsna-buf deleted the sk/expand-celtype branch January 15, 2026 11:37
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.

3 participants