{"record":{"id":"391ff647f3ea264d","repo":"redis/redis-py","slug":"himport-fieldset-must-have-at-least-one-field","errorCode":null,"errorMessage":"HIMPORT fieldset must have at least one field","messagePattern":"HIMPORT fieldset must have at least one field","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/himport.py","lineNumber":248,"sourceCode":"        can be slow, or -- for a generator that inspects this same registry -- can\n        re-enter a locked read (e.g. ``yield`` then ``registry.names()``). Running\n        it under the non-reentrant ``_lock`` would stall every registry user or\n        deadlock permanently. Field order is preserved; nothing is reordered or\n        deduplicated.\n        \"\"\"\n        # A bare single field name (str/bytes/bytearray/memoryview) is itself\n        # iterable element-by-element; that is almost certainly a caller mistake and\n        # would silently register single-character/single-byte \"fields\" (e.g.\n        # memoryview(b\"id\") -> field names 105, 100), so reject it as invalid local\n        # API usage. int/float are not iterable, so tuple() below rejects them.\n        if isinstance(fields, (str, bytes, bytearray, memoryview)):\n            raise DataError(\n                \"HIMPORT fields must be a collection of field names, \"\n                \"not a single string or binary value\"\n            )\n        field_tuple = tuple(fields)\n        if not field_tuple:\n            raise DataError(\"HIMPORT fieldset must have at least one field\")\n        return field_tuple\n\n    def _set(self, name: str, field_tuple: tuple) -> HImportFieldset:\n        # ``field_tuple`` is already validated/materialized by\n        # :meth:`_materialize_fields`; only the (cheap, non-blocking) revision bump\n        # and dict mutation run here, so ``_lock`` is never held across arbitrary\n        # caller code.\n        fieldset = HImportFieldset(\n            name=name,\n            fields=field_tuple,\n            version=self._advance(),\n        )\n        self._fieldsets[name] = fieldset\n        return fieldset\n\n    # -- mutation ---------------------------------------------------------\n\n    def prepare(self, name: str, fields: Iterable[FieldT]) -> HImportFieldset:","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/himport.py#L230-L266","documentation":"_materialize_fields (redis/himport.py:248) rejects an empty field collection with DataError('HIMPORT fieldset must have at least one field'). After converting the caller's iterable to a tuple, a zero-length result is invalid because an HIMPORT fieldset with no fields has no server-side meaning and would produce a no-op/erroneous HIMPORT PREPARE.","triggerScenarios":"registry.prepare('users', []) ; prepare('users', ()) ; passing an empty generator; passing a list that was filtered down to zero elements.","commonSituations":"Computing the field list from a config/schema that happened to be empty in a test/staging environment; a filter that removed everything; defaulting fields to [] when none configured.","solutions":["Ensure the field iterable contains at least one name before calling prepare.","Skip the prepare call (and the HIMPORT feature) entirely when the field set is empty.","Add a config-time assertion so an empty schema fails loudly during startup, not at prepare time."],"exampleFix":"// before\nregistry.prepare('users', fields_from_config)\n// after\nif fields_from_config:\n    registry.prepare('users', fields_from_config)\nelse:\n    log.warning('no HIMPORT fields configured for users; skipping')","handlingStrategy":"validation","validationCode":"fields = list(fields_src)\nassert fields, 'HIMPORT fieldset must have at least one field'\nif fields:\n    registry.prepare('users', fields)","typeGuard":"def has_fields(fields) -> bool:\n    return not isinstance(fields, (str, bytes, bytearray, memoryview)) and len(list(fields)) > 0","tryCatchPattern":null,"preventionTips":["Skip prepare when the field set is empty rather than registering a no-op fieldset.","Validate schemas at config load time so empty field lists fail early.","Log when an empty field list is encountered so it is observable."],"tags":["himport","validation","data-error","fields"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}