Skip to content

Configuration option to use latest schema version instead of compatibility testing. - #61

Open
torgeirsh wants to merge 1 commit into
haskell-works:mainfrom
torgeirsh:latest
Open

torgeirsh wants to merge 1 commit into
haskell-works:mainfrom
torgeirsh:latest

Conversation

@torgeirsh

Copy link
Copy Markdown
Contributor

Fixes #60. @mrcjkb

Comment on lines -162 to +182
Right (RegisteredSchema schema, schemaId) -> cacheSchema sr schemaId schema $> Right schema
Right (RegisteredSchema schema, schemaId) -> do
cacheId sr subject (fullTypeName schema) schemaId
cacheSchema sr schemaId schema

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The lack of id caching seems to have been an existing bug, since getCompatibleSchema expects to look up by id after calling loadSubjectSchema.

let url = srBaseUrl sr ++ "/subjects/" ++ unpack sbj ++ "/versions/" ++ show version
loadSubjectSchema registry subject version = fmap snd <$> loadSubjectSchema' registry subject (SpecificVersion version)

loadSubjectSchema' :: MonadIO m => SchemaRegistry -> Subject -> QueryVersion -> m (Either SchemaRegistryError (SchemaId, Schema))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Modifying loadSubjectSchema would be a breaking change, so I left this improved version "primed" and hidden for now. It could perhaps replace the original in a future major version.

@mrcjkb mrcjkb left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not a maintainer of this package.
You should probably ping @AlexeyRaga for review.

But I do have some suggestions...

Comment on lines 71 to +76
newtype Version = Version { unVersion :: Word32 } deriving (Eq, Ord, Show, Hashable)
data QueryVersion = SpecificVersion Version | LatestVersion
renderQueryVersion :: QueryVersion -> String
renderQueryVersion = \case
SpecificVersion (Version version) -> show version
LatestVersion -> "latest"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quibble:

Suggested change
newtype Version = Version { unVersion :: Word32 } deriving (Eq, Ord, Show, Hashable)
data QueryVersion = SpecificVersion Version | LatestVersion
renderQueryVersion :: QueryVersion -> String
renderQueryVersion = \case
SpecificVersion (Version version) -> show version
LatestVersion -> "latest"
newtype Version = Version { unVersion :: Word32 } deriving (Eq, Ord, Show, Hashable)
data QueryVersion = SpecificVersion Version | LatestVersion
renderQueryVersion :: QueryVersion -> String
renderQueryVersion = \case
SpecificVersion (Version version) -> show version
LatestVersion -> "latest"

Comment on lines +149 to +153
-- | When auto-registration of schemas is disabled, pick the latest version instead of using compatibility testing.
-- This is similar to the Confluent 'use.latest.version' option.
cfgUseLatestSchemaVersion :: Bool -> SchemaRegistryConfig -> SchemaRegistryConfig
cfgUseLatestSchemaVersion useLatestSchemaVersion config = config { cUseLatestSchemaVersion = useLatestSchemaVersion }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion:

Adding this config option adds some complexity to the UX.
It's possible to set cfgAutoRegisterSchemas = True and cfgUseLatestSchemaVersion = True - which is a conflict. And I don't think Haddock explaining that cfgAutoRegisterSchemas has higher priority improves the UX.

I'd suggest to remove this config option. Instead, in the case where cfgAutoRegisterSchemas == False:

  • Check if the latest schema version is compatible.
  • If not, fall back to getCompatibleSchema.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! The point of the option is to bypass compatibility testing in cases when you don't have permission, so a check with fallback unfortunately won't work. I realise that the auto registration option will take precedence, but that's also the case with the official Confluent library, and I figured it was best if the behaviour is similar. Otherwise, another option would've been to merge the two options and use a three-way sum type instead of a boolean, but that breaks compatibility.

@mrcjkb mrcjkb Mar 6, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Right 😅

Personally, if it improves the UX, I'd prefer a sum type even if it's a breaking change (After all, PVP and SemVer exist to reduce the pain of dealing with breaking changes - and this package hasn't been very actively maintained lately anyway).
But that's not up to decide, so I'd suggest to wait for feedback from @AlexeyRaga.

@AlexeyRaga

Copy link
Copy Markdown
Member

Sorry, I commented in details here, but to me it looks like that the whole thing about using arbitrary schema IDs instead of registering real schemas doesn't look right.

We should stop and rethink the matter.

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.

Compatibility testing and read-only schema registry

3 participants