Skip to content

Mockgun: return default values in the types the server returns - #467

Open
patrickwolf wants to merge 1 commit into
shotgunsoftware:masterfrom
patrickwolf:mockgun-default-value-types
Open

patrickwolf wants to merge 1 commit into
shotgunsoftware:masterfrom
patrickwolf:mockgun-default-value-types

Conversation

@patrickwolf

Copy link
Copy Markdown

Problem

A new record takes each field's default straight from the schema's default_value, in whatever form the schema stores it. In the schema shipped in tests/mockgun, 9 checkbox fields have None as their default (for example Project.current_user_favorite) and 4 text fields have "" (for example HumanUser.email). Schemas read from newer sites can also store a number's default as a string such as "0". The server returns False, None and 0 for these, so code that checks is False or does arithmetic behaves differently under Mockgun.

Change

_get_default_value converts the default the way the server returns it: a checkbox to a bool, empty text to None, and a number, percent, duration or timecode stored as a string to an int (a float or currency to a float). _get_new_row now uses _get_default_value instead of repeating its logic.

Tests

TestDefaultValues: an unset checkbox is False, empty text is None, and a number default stored as "0" is 0 (the test changes the shared schema and restores it afterwards).

python -m pytest tests/test_mockgun.py

Merge order

Independent of the other Mockgun PRs (field types, limit and page, upload), but each of them also adds its test class at the end of tests/test_mockgun.py. Whichever is merged later needs a rebase that keeps both test classes.

New records took their defaults from the schema as stored: an unset checkbox could be None, empty text "", and a number the string "0". The server returns False, None and 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@patrickwolf
patrickwolf force-pushed the mockgun-default-value-types branch from ca9f564 to 3d389ba Compare November 16, 2026 17:45

This branch has not been deployed

No deployments
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