apache/pulsar · error · Exception

Invalid schema class %s

Error message

Invalid schema class %s

What it means

python_instance.get_schema builds a schema object from the configured schema type and record class. If the resolved schema class accepts fewer than the required constructor arguments (args_count < 3 fallback path and no matching branch), Pulsar raises Exception('Invalid schema class %s') — the configured schema class is not a supported Avro/JSON-style schema that can be instantiated with the record class and schema properties.

Source

Thrown at pulsar-functions/instance/src/main/python/python_instance.py:574

    else:  # load custom schema
      record_kclass = self.get_record_class(type_class_name)
      schema_kclass = util.import_class(os.path.dirname(self.user_code), schema_type)
      args_count = 0
      try:
        args_count = len(inspect.signature(schema_kclass.__init__).parameters)
      except:  # for compatibility with python 2
        args_count = len(inspect.getargspec(schema_kclass.__init__).args)
      if args_count == 1:  # doesn't take any arguments
        schema = schema_kclass()
      elif args_count == 2:  # take one argument, it can be either schema properties or record class
        try:
          schema = schema_kclass(record_kclass)
        except TypeError:
          schema = schema_kclass(schema_properties)
      elif args_count >= 3:  # take two or more arguments
        schema = schema_kclass(record_kclass, schema_properties)
      else:
        raise Exception("Invalid schema class %s" % schema_type)
    return schema

  def get_record_class(self, class_name):
      record_kclass = None
      if class_name != None and len(class_name) > 0:
        try:
          record_kclass = util.import_class(os.path.dirname(self.user_code), class_name)
        except:
          pass
      return record_kclass
  def get_negative_ack_args(self):
    """Build the negative-ack redelivery delay argument for Client.subscribe().

    Returns a dict to splat into the subscribe() call: either empty, or carrying
    negative_ack_redelivery_delay_ms.

    SourceSpec.negativeAckRedeliveryDelayMs is a proto3 scalar with no presence, so an unset field
    reads as 0. Only a positive value is forwarded, leaving the client default (60s) in place

View on GitHub (pinned to 820761864e)

Solutions

  1. Use a supported schema type (avro/json/protobuf) with a valid record class, or omit schema config for builtin types.
  2. Give the custom schema class a constructor accepting (record_class, schema_properties) or at least one argument that matches the branch conditions.
  3. Verify get_record_class resolves the configured recordClassName to a real Python class.
  4. Log args_count and schema_type to see which instantiation branch was expected.

Example fix

# before
class MySchema:
    def __init__(self):  # no args — unsupported
        ...
# after
class MySchema:
    def __init__(self, record_class, schema_properties=None):
        ...
Defensive patterns

Strategy: validation

Validate before calling

import inspect
sig = inspect.signature(MySchema.__init__)
assert len(sig.parameters) >= 2 or any(
    p.default is not inspect.Parameter.empty for p in list(sig.parameters.values())[1:]), \
    'schema class constructor incompatible'

Try / catch

try:
    schema = InstanceConfig.get_schema(schema_type)
except Exception as e:
    logging.error('schema class %s not instantiable: %s', schema_type, e)

Prevention

When it happens

Trigger: Configuring a custom or built-in schema class whose __init__ accepts zero or one argument such that args_count branches all fail; passing schemaType that maps to a class incompatible with the resolved record class; get_schema called from run or setup_producer when output schema data is misconfigured.

Common situations: Custom schema class with a nonstandard constructor signature; using a schema type (e.g. 'string' or 'void') in a context requiring a record class; record class resolution failing so record_kclass/schema_properties combination matches no branch.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/4628920b673dbafb. Report an issue: GitHub.