22. Add CharmSpecific fields

The implementation of CharmSpecific callbacks in 24. Implement refresh_snap and 29. Implement pre-refresh checks may require you to add fields to your CharmSpecific class.

The implementation of the is_compatible callback must not use additional fields

Since CharmSpecific is a dataclass, use the dataclasses syntax to add fields.

Example: Add _charm field
@dataclasses.dataclass(eq=False)
class PostgreSQLRefresh(charm_refresh.CharmSpecificCommon, abc.ABC):
    _charm: "PostgreSQLCharm" (1)

    def run_pre_refresh_checks_after_1_unit_refreshed(self) -> None:
        if self._charm.backup_in_progress: (2)
            # [...]

class PostgreSQLCharm(ops.CharmBase):
    def __init__(self, *args):
        # [...]

        self.refresh = charm_refresh.Kubernetes(
            KubernetesPostgreSQLRefresh(
                workload_name="PostgreSQL",
                charm_name="postgresql-k8s",
                oci_resource_name="postgresql-image",
                _charm=self, (3)
            )
        )

        # [...]
1 Add _charm field
2 Example usage in CharmSpecific callback
3 Pass the field in the instantiation of your CharmSpecific class