Skip to content

Use default_factory for OrderResponse order_id and created_at - #1

Open
Wired4ncer wants to merge 1 commit into
smallworlnd:mainfrom
Wired4ncer:fix/order-response-per-instance-defaults
Open

Use default_factory for OrderResponse order_id and created_at#1
Wired4ncer wants to merge 1 commit into
smallworlnd:mainfrom
Wired4ncer:fix/order-response-per-instance-defaults

Conversation

@Wired4ncer

Copy link
Copy Markdown

While reading through publsp closely (considering helping revive it), I noticed OrderResponse.order_id and OrderResponse.created_at use plain default values rather than default factories:

order_id: str = str(uuid.uuid4())
created_at: int = int(time.time())

Because these are evaluated once, at class-definition (import) time, every OrderResponse constructed without explicit values shares the same order_id and the same created_at for the lifetime of the process. Two orders created in one run would collide on order_id and report an import-time timestamp instead of their real creation time.

Fix

Switch both to default_factory so each instance gets a fresh value:

order_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
created_at: int = Field(default_factory=lambda: int(time.time()))

Tests

Adds tests/test_order_response_defaults.py — asserts two OrderResponse instances get distinct order_ids and monotonic/independent created_ats. Node-free (no LND connection needed), so it runs in CI as-is.

All up for discussion — happy to adjust naming or style to match your conventions.

🤖 Generated with Claude Code

Field(default=str(uuid.uuid4())) and Field(default=datetime.now(timezone.utc))
are evaluated once at class-definition time, so every OrderResponse built
without an explicit value shared a single frozen order_id and a single frozen
created_at timestamp. Switch both to default_factory so they are produced per
instance.

Adds tests/test_order_response_defaults.py (no node/relay required).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant