Skip to content

_base

_base

DomoAccount_Config dataclass

DomoAccount_Config(
    data_provider_type: str,
    is_oauth: bool,
    allow_external_use: bool = True,
    parent: Any = None,
    raw: dict = None,
)

Bases: DomoBase

DomoAccount Config abstract base class

from_dict classmethod

from_dict(
    obj: dict[str, Any], parent: Any = None, **kwargs
)

Create instance from dict, handling camelCase, snake_case, and _field_map. Robust to missing or None _field_map. Uses _field_map for both directions.

Source code in src/crew_dcs/classes/DomoAccount/account_configs/_base.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@classmethod
def from_dict(cls, obj: dict[str, Any], parent: Any = None, **kwargs):
    """
    Create instance from dict, handling camelCase, snake_case, and _field_map.
    Robust to missing or None _field_map. Uses _field_map for both directions.
    """
    # Get _field_map from dataclass field's default_factory if it exists
    field_map = {}
    if (
        hasattr(cls, "__dataclass_fields__")
        and "_field_map" in cls.__dataclass_fields__
    ):
        field_def = cls.__dataclass_fields__["_field_map"]
        if field_def.default_factory:
            field_map = field_def.default_factory()

    # Build a reverse map for input keys that are snake_case but need to be mapped to camelCase
    reverse_map = {
        v: k for k, v in field_map.items()
    }  # {"passphrase" : "passPhrase"}

    init_kwargs = {}

    init_kwargs.update(kwargs)

    for k, v in obj.items():
        if k in ["_search_metadata"]:
            continue

        # Try direct field_map, then reverse_map, then camel_to_snake
        if k in field_map:
            attr = field_map[k]

        elif k in reverse_map:
            attr = reverse_map[k]

        else:
            attr = cls._camel_to_snake(k)

        init_kwargs[attr] = v

    return cls(parent=parent, raw=obj, **init_kwargs)

to_dict

to_dict(
    export_fields: list[str] | None = None,
    override_fn: Callable | None = None,
    return_snake_case: bool = False,
    **kwargs
) -> dict

Convert config to dictionary using provided fields or all _fields_for_serialization.

Source code in src/crew_dcs/classes/DomoAccount/account_configs/_base.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
def to_dict(
    self,
    export_fields: list[str] | None = None,
    override_fn: Callable | None = None,
    return_snake_case: bool = False,
    **kwargs,
) -> dict:
    """
    Convert config to dictionary using provided fields or all _fields_for_serialization.
    """
    result = {"allowExternalUse": self.allow_external_use}

    # Use all fields_for_serialization if not provided
    export_fields = [
        key
        for key in (
            export_fields
            or self._fields_for_serialization
            or self.__dataclass_fields__.keys()
        )
        if key
        not in [
            "raw",
            "_field_map",
            "_fields_for_serialization",
            "is_oauth",
            "data_provider_type",
            "__serialize_properties__",
        ]
    ]

    reverse_map = {v: k for k, v in self._field_map.items()}

    for attr in export_fields:
        val = getattr(self, attr, None)
        if val is not None:
            key = reverse_map.get(attr, self._snake_to_camel(attr))
            result[key] = val

    result.update(kwargs)

    if return_snake_case:
        result = {self._camel_to_snake(k): v for k, v in result.items()}

    if override_fn:
        result = override_fn(self)

    return result

validate_compare_serialization

validate_compare_serialization(
    raise_on_mismatch: bool = True,
) -> bool

Validate that to_dict() output matches raw data keys (ignoring values).

Parameters:

Name Type Description Default
raise_on_mismatch bool

If True, raises AccountConfig_SerializationMismatchError on mismatch. If False, returns False on mismatch.

True

Returns:

Type Description
bool

True if keys match, False otherwise (only if raise_on_mismatch=False)

Raises:

Type Description
AccountConfig_SerializationMismatchError

If keys don't match and raise_on_mismatch=True

Source code in src/crew_dcs/classes/DomoAccount/account_configs/_base.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def validate_compare_serialization(self, raise_on_mismatch: bool = True) -> bool:
    """
    Validate that to_dict() output matches raw data keys (ignoring values).

    Args:
        raise_on_mismatch: If True, raises AccountConfig_SerializationMismatchError on mismatch.
                         If False, returns False on mismatch.

    Returns:
        True if keys match, False otherwise (only if raise_on_mismatch=False)

    Raises:
        AccountConfig_SerializationMismatchError: If keys don't match and raise_on_mismatch=True
    """
    if not self.raw:
        return True

    to_dict_keys = set(self.to_dict(return_snake_case=False).keys())
    raw_keys = set(self.raw.keys()) - {"_search_metadata", "data_provider_type"}

    only_in_to_dict = to_dict_keys - raw_keys
    only_in_raw = raw_keys - to_dict_keys

    has_mismatch = bool(only_in_to_dict or only_in_raw)

    if has_mismatch and raise_on_mismatch:
        account_id = self.raw.get("_search_metadata", {}).get(
            "account_id", "unknown"
        )
        raise AccountConfig_SerializationMismatchError(
            cls_instance=self,
            data_provider_type=self.data_provider_type,
            account_id=str(account_id),
            only_in_to_dict=dict.fromkeys(only_in_to_dict),
            only_in_raw=dict.fromkeys(only_in_raw),
            value_mismatches={},
        )

    return not has_mismatch