Skip to content

models: add named integer enum types - #178

Open
mihaimarcu2004 wants to merge 1 commit into
mainfrom
devin/1790333761-integer-enum-models
Open

mihaimarcu2004 wants to merge 1 commit into
mainfrom
devin/1790333761-integer-enum-models

Conversation

@mihaimarcu2004

@mihaimarcu2004 mihaimarcu2004 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Comment thread lighter/models/account.py
Comment on lines +46 to +51
@field_validator('account_type')
def account_type_validate_enum(cls, value):
"""Validates the enum"""
if value not in set([0, 1, 2, 3, 4, 5]):
raise ValueError("must be one of enum values (0, 1, 2, 3, 4, 5)")
return value

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Valid integer values rejected by models

When Account receives an unlisted integer account type, account_type_validate_enum rejects it. The schema allows integers without an enum restriction, so valid model construction and assignment fail. Other new validators impose the same restriction on trading modes, margin modes, pool statuses, and RFQ directions.

Learn more

The bundled OpenAPI schema declares these fields as integers rather than enumerations. A named constant can describe known values without changing the accepted value range. The new validators run for direct Pydantic construction and assignment, while the generated from_dict path uses model_construct and does not invoke them. This makes construction reject integers that the SDK previously accepted and that the schema still permits. The same restriction appears on the new validators in DetailedAccount, AccountPosition, MarketConfig, PublicPoolInfo, PublicPoolMetadata, and the RFQ response and entry models.

Example: A caller creates an Account with account_type=6 after the service adds a new account type. The bundled integer schema accepts 6, but direct construction raises ValidationError; Account.from_dict accepts the same value.

Recommended fix: Keep the named enum classes as optional constants but remove the closed-set validators until the API contract itself declares closed enum values. If the API contract is intentionally closed, update the OpenAPI schemas and regenerate all affected SDK models together.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +36 to +39
@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of AccountAccountTypeEnum from a JSON string"""
return cls(json.loads(json_str))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Noninteger JSON becomes a valid enum

When AccountAccountTypeEnum.from_json receives true or 1.0, it returns Sub instead of rejecting noninteger JSON. All added enums use the same conversion, silently misclassifying malformed values.

Learn more

Every added integer enum calls its constructor on the result of json.loads. In Python, True == 1 and 1.0 == 1, so integer enum lookup accepts both and returns the member with value 1. These enum classes represent integer JSON fields; the model fields themselves use StrictInt for the same properties.

Example: AccountAccountTypeEnum.from_json('true') returns AccountAccountTypeEnum.Sub, although true is a JSON boolean, not account type 1.

Recommended fix: Parse JSON and require type(value) is int before converting it to an enum member. Apply this check consistently across all new enum from_json implementations.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread lighter/models/account.py
Comment on lines +31 to +32
account_type: StrictInt = Field(description="See AccountAccountTypeEnum")
account_trading_mode: StrictInt = Field(description="Classic=0 and Unified=1. See AccountAccountTradingModeEnum")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Response fields remain plain integers

The new enum classes do not change StrictInt model fields. API responses still expose integers, not members with .name; clarify whether the enums are only intended as constants.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +29 to +30
Simple = 0
Unified = 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Trading mode zero has two names

The enum calls mode 0 Simple, while the account field description calls it Classic. Clarify which public name consumers can rely on.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants