spring-cloud / spring-cloud-schema-registry

A schema registry implementation for Spring Cloud Stream
47 stars 28 forks source link

avro schema client bug | not using latest schema but reporting latest version #48

Open nhomble opened 3 years ago

nhomble commented 3 years ago

We see an issue where producers of data are using version 1 of a schema when the registry has up to version 2 (backwards compatible). When the spring cloud client gets the available schemas for the subject, it picks the latest version but it doesn't change the actual schema object.

https://github.com/spring-cloud/spring-cloud-schema-registry/commit/740c811d6ced20f2d6668282d17c25ea7f71f256

    ResponseEntity<List> response = this.template.getForEntity(this.endpoint + "/subjects/" + subject + "/versions",
            List.class);
        final List body = response.getBody();
    if (!CollectionUtils.isEmpty(body)) {
        version = (Integer) body.get(body.size() - 1);
    }

This seems like incorrect behavior. It makes sense to use the latest version because of compatibility assertions but when you do, you need to use the actual schema for that id. For comparison, we can see confluent's serializer

      } else if (useLatestVersion) {
        restClientErrorMsg = "Error retrieving latest version of Avro schema";
        schema = (AvroSchema) lookupLatestVersion(subject, schema);
        id = schemaRegistry.getId(subject, schema);
      }

here they get both latest id and version while writing. But in the spring cloud code, we are only using the List.class response to get the size of the list (number of schemas).