haive.core.common.mixins.general.version

Version mixin for tracking object versions.

This module provides a mixin for adding version tracking to Pydantic models. It tracks the current version and maintains a history of previous versions, which is useful for auditing, compatibility checking, and change tracking.

Usage:

from pydantic import BaseModel from haive.core.common.mixins.general import VersionMixin

class Document(VersionMixin, BaseModel):

title: str content: str

# Create a document with default version 1.0.0 doc = Document(title=”Example”, content=”Content”)

# Make changes and bump version doc.content = “Updated content” doc.bump_version(“1.1.0”)

# Check version history history = doc.get_version_history() # [‘1.0.0’, ‘1.1.0’]

Classes

VersionMixin

Mixin for adding version tracking to Pydantic models.

Module Contents

class haive.core.common.mixins.general.version.VersionMixin(/, **data)[source]

Bases: pydantic.BaseModel

Mixin for adding version tracking to Pydantic models.

This mixin adds version information to any model, with support for tracking version history. It’s useful for managing model versions, checking compatibility, and auditing changes over time.

Parameters:

data (Any)

version

Current version string (defaults to “1.0.0”).

version_history

List of previous versions.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

bump_version(new_version)[source]

Update version and track the previous version in history.

This method should be called whenever a significant change is made to the object that warrants a version increment.

Parameters:

new_version (str) – The new version string to set.

Return type:

None

get_version_history()[source]

Get complete version history including the current version.

Returns:

List containing all previous versions plus the current version.

Return type:

list[str]