Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Nov 20, 2024

Updates the protovalidate version to 0.8.2 and fixes three closely-related bugs:

  • rule is inadvertently typed incorrectly when it is a repeated rule field on a repeated field
  • getCELType inadvertently returns an incorrectly-named message type when dealing with a message field (using the full name of the field instead of the full name of the type)
  • getCELType returns a message type instead of a wrapper type for wrappers like google.protobuf.Int32Value

These bugs are subtle because they don't occur in normal circumstances, but the new predefined rule tests added in v0.8.2 to close the bugs on protovalidate-go inadvertently revealed several protovalidate-java bugs. This validates that more work on the conformance test can still be quite valuable in finding difficult bugs, even if we don't know exactly what we're looking for.

@ghost ghost requested review from Alfus and jhump November 20, 2024 18:22
@@ -243,7 +243,7 @@ private Env getRuleEnv(
Variable.RULES_NAME,
Decls.newObjectType(constraintMessage.getDescriptorForType().getFullName())),
Decls.newVar(
Variable.RULE_NAME, DescriptorMappings.getCELType(constraintFieldDesc, forItems))));
Variable.RULE_NAME, DescriptorMappings.getCELType(constraintFieldDesc, false))));
Copy link
Author

Choose a reason for hiding this comment

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

Explanation: The forItems in this context is for the field, not the rule. We never act on the nested items of the rule individually, so forItems should always be false for the rule type.

return Decls.newWrapperType(Decls.String);
case "google.protobuf.UInt32Value":
case "google.protobuf.UInt64Value":
return Decls.newWrapperType(Decls.Uint);
Copy link
Author

Choose a reason for hiding this comment

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

Explanation: In most cases, the wrapper type is "unwrapped" by having its constraints processed in processWrapperConstraints; in other cases (e.g. nested in a message), it is handled by cel-java. However, in the case of the rule, we might be dealing with a wrapper or repeated wrapper directly. Therefore,getCELType needs to be aware of wrappers.

default:
return Decls.newObjectType(fieldDescriptor.getFullName());
return Decls.newObjectType(fqn);
Copy link
Author

@ghost ghost Nov 20, 2024

Choose a reason for hiding this comment

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

Explanation: newObjectType sets the typeName field passed to setMessageType. I think in most cases this field doesn't actually matter (presumably because cel-java is doing protobuf reflection on the runtime value anyways) but having this set wrong makes the error messages unintelligible. Set it to the fqn of the message type instead of the field descriptor full name.

@ghost ghost merged commit 460804a into main Nov 20, 2024
3 checks passed
@ghost ghost deleted the jchadwick/predefined-fixes branch November 20, 2024 18:51
@ghost ghost changed the title Fixes for complex predefined field types Fixes for complex predefined rule types Nov 20, 2024
This pull request was closed.
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.

1 participant