Skip to content

Consider simplifying default model_key_prefix #741

@abrookins

Description

@abrookins

Summary

The default model_key_prefix currently includes the full module path (e.g., myapp.models.User), which can be problematic:

  1. Fragile to refactoring - Moving a model file or renaming a module breaks existing Redis keys
  2. Verbose keys - Keys become unnecessarily long
  3. Inconsistent with SQL ORMs - Most ORMs use just the class name for table names

Current behavior

class User(HashModel):
    name: str

# Keys look like: myapp.models.User:abc123

Proposed behavior

class User(HashModel):
    name: str

# Keys would look like: User:abc123

Considerations

This is a breaking change that requires careful handling:

  • Existing keys would become orphaned after upgrade
  • Two models with the same class name in different modules would collide
  • Need migration path or documentation for users upgrading

Prior work

PR #522 attempted this change but was closed due to staleness. The implementation was simple (just use __name__ instead of __module__.__name__), but the migration/breaking change concerns need to be addressed.

Options

  1. Major version bump with clear migration docs
  2. Opt-in flag to use simplified prefix (non-breaking)
  3. Keep current behavior but improve documentation (Document model_key_prefix usage #364)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions