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

When referring to other Protobuf schemas from a schema, only references are required and import statements are ignored. #738

Open
roope-kar opened this issue Oct 17, 2023 · 0 comments

Comments

@roope-kar
Copy link
Contributor

roope-kar commented Oct 17, 2023

What happened?

When creating a Protobuf schema with references, types from the referred schemas can be used even without actually importing them in the schema itself.

  1. Create schema A by sending a POST request over subjects/mySubjectA/versions with the following body:
{
    "schema": "syntax = \"proto3\";\nmessage MyType {\n  int32 id = 1;\n}",
    "schemaType": "PROTOBUF"
}
  1. Create schema B by sending a POST request over subjects/mySubjectB/versions with the following body:
{
    "schema": "syntax = \"proto3\";\nmessage MyRecord {\n  string f1 = 1;\n  MyType f2 = 2;\n}",
    "schemaType": "PROTOBUF",
    "references": [
        {
            "name": "mySubjectA",
            "subject": "mySubjectA",
            "version": 1
        }
    ]
}

Creating schema succeeds without import statement.
Creating fails, if you remove the references.
This would imply that import statement is ignored and only the references are read.

What did you expect to happen?

Creating schema would fail if types are used from the referred schema without actually importing.

The following test should throw an exception but doesn't:

def test_invalid_import() -> None:
   plan = """\
    syntax = "proto3";

    package my.package;

    message ExternalMessage {
      string field = 1;
    }
    """

    customer_plan_event = """\
    syntax = "proto3";

    package another.package;

    message CustomerPlanEvent {
      message Created {
        my.package.ExternalMessage message = 1;
      }
    }
    """

    no_ref_schema = ValidatedTypedSchema.parse(SchemaType.PROTOBUF, plan)
    dep = Dependency("this_is_ignored", Subject("this_also"), 1, no_ref_schema)
    ref_schema = ValidatedTypedSchema.parse(SchemaType.PROTOBUF, customer_plan_event, None, {"foobar": dep})

We are apparently ignoring both the name and the subject and we are relying on the fact that the reference map is in sync with the import statements

What else do we need to know?

Tested only with Protobuf schemas, did not try with other schema types.

@roope-kar roope-kar changed the title When referring to other Protobuf schemas in schema - only references are required and import statements are ignored. When referring to other Protobuf schemas from a schema - only references are required and import statements are ignored. Oct 17, 2023
@roope-kar roope-kar changed the title When referring to other Protobuf schemas from a schema - only references are required and import statements are ignored. When referring to other Protobuf schemas from a schema, only references are required and import statements are ignored. Oct 17, 2023
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

No branches or pull requests

1 participant