1from typing import Any
2
3from plain import models
4
5
6def coerce_key(key: Any) -> str:
7 """
8 Converts a flag key to a string for storage in the DB
9 (special handling of model instances)
10 """
11 if isinstance(key, str):
12 return key
13
14 if isinstance(key, models.Model):
15 return (
16 f"{key.model_options.package_label}.{key.model_options.model_name}:{key.id}"
17 )
18
19 return str(key)