Skip to content

fix(spp_registry): drop non-writeable @constrains('age') load warning - #357

Open
reichie020212 wants to merge 5 commits into
19.0from
fix/registry-age-constrains-not-writeable
Open

fix(spp_registry): drop non-writeable @constrains('age') load warning#357
reichie020212 wants to merge 5 commits into
19.0from
fix/registry-age-constrains-not-writeable

Conversation

@reichie020212

@reichie020212 reichie020212 commented Jul 24, 2026

Copy link
Copy Markdown
Member

Problem

At every registry load, spp_registry logs:

WARNING ... odoo.models: method res.partner._check_age_is_integer: @constrains parameter 'age' is not writeable

Infra reports this warning as deployment-log noise on the 4Ps preprod stack.

Root cause

res.partner.age (spp_registry/models/individual.py) is a non-stored computed field:

age = fields.Char(compute="_compute_calc_age", size=50, readonly=True)

@api.constrains("age") on a non-stored compute is exactly what Odoo warns about — constrains hooks only run on stored writes, so _check_age_is_integer never actually fired. It was also redundant: age is fully derived from birthdate (str(years), or "No Birthdate!"), so it can never carry user-supplied input.

Fix

Remove the dead @api.constrains("age") / _check_age_is_integer guard. The age field, its _compute_calc_age compute, and compute_age_from_dates are unchanged, so every computed age value is produced exactly as before — behavior-preserving. The existing creation regression tests are kept.

Cleanup shipped with the removal:

  • Stale i18n entries for the removed "Age must be a valid integer." message dropped from es.po, fr.po, and spp_registry.pot.
  • Test class TestCheckAgeIsInteger (named after the removed method) renamed to TestAgeCreationBehavior, and its docstring corrected: a plain @api.constrains("birthdate") would not fire on a create that omits birthdate, so only the stored-compute variant is the naive re-introduction the tests guard against.
  • Version bump spp_registry19.0.2.1.4 + readme/HISTORY.md entry (README regen via CI's pinned generator).

Note (pre-existing, out of scope)

age can still be a negative string (e.g. "-3") when birthdate is set to a future date via ORM/import/API — only the _birthdate_onchange guard (UI form) blocks future dates. The removed constraint never caught this either (non-stored compute), so this PR doesn't change that behavior. Follow-up tracked in #362: add @api.constrains("birthdate") rejecting future dates (writeable field → no warning, and covers ORM/import).

Base

Originally branched from 7973bef (the commit deployed on 4Ps preprod) so the fix could be verified against that stack. origin/19.0 has since been merged into the branch so the 19.0.2.1.4 version bump sits on top of 19.0.2.1.3 without manifest/HISTORY conflicts. The code diff vs 19.0 remains: the constraint removal, the i18n/test cleanup, and the version bump.

`age` is a non-stored compute derived from `birthdate`, so
`@api.constrains("age")` never fired — Odoo only runs constrains on
stored writes — and it emitted this warning at every registry load:

    method res.partner._check_age_is_integer: @constrains parameter
    'age' is not writeable

The check was also redundant: `age` is fully derived from `birthdate`
and can never carry user-supplied input, so `_check_age_is_integer` is
removed as dead code. The `age` field, its `_compute_calc_age` compute,
and `compute_age_from_dates` are unchanged, so every computed `age`
value behaves exactly as before. Existing creation regression tests are
kept; the stale constraint docstring is updated to record the removal.

Signed-off-by: Red <redickbutay02@gmail.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@reichie020212
reichie020212 force-pushed the fix/registry-age-constrains-not-writeable branch from 3e73f77 to a8c9bc9 Compare July 24, 2026 11:43
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.26%. Comparing base (1caf794) to head (38c230e).
⚠️ Report is 3 commits behind head on 19.0.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #357      +/-   ##
==========================================
- Coverage   74.28%   72.26%   -2.03%     
==========================================
  Files         372     1011     +639     
  Lines       25385    60736   +35351     
==========================================
+ Hits        18857    43890   +25033     
- Misses       6528    16846   +10318     
Flag Coverage Δ
spp_analytics 93.25% <ø> (+0.11%) ⬆️
spp_api_v2 79.99% <ø> (?)
spp_api_v2_change_request 66.53% <ø> (?)
spp_api_v2_cycles 71.03% <ø> (+0.38%) ⬆️
spp_api_v2_data 77.77% <ø> (?)
spp_api_v2_entitlements 70.23% <ø> (+0.27%) ⬆️
spp_api_v2_gis 71.57% <ø> (+0.04%) ⬆️
spp_api_v2_products 65.86% <ø> (?)
spp_api_v2_programs 92.22% <ø> (+0.19%) ⬆️
spp_api_v2_service_points 71.03% <ø> (?)
spp_api_v2_simulation 71.19% <ø> (+0.07%) ⬆️
spp_api_v2_vocabulary 57.75% <ø> (?)
spp_approval 50.34% <ø> (?)
spp_area 80.16% <ø> (?)
spp_area_hdx 81.60% <ø> (?)
spp_audit 72.13% <ø> (?)
spp_base_common 91.07% <ø> (+0.80%) ⬆️
spp_dci_compliance ?
spp_dci_server_social ?
spp_programs 65.27% <ø> (+<0.01%) ⬆️
spp_registry 87.22% <ø> (+0.39%) ⬆️
spp_security 69.56% <ø> (+2.89%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
spp_registry/models/individual.py 89.58% <ø> (+2.45%) ⬆️

... and 712 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…moved age constraint

The 'Age must be a valid integer.' msgid no longer exists in code; remove
it from es.po, fr.po and the .pot. Rename TestCheckAgeIsInteger (named
after the removed method) to TestAgeCreationBehavior and correct the
docstring: a plain @api.constrains('birthdate') would not fire on a
create that omits birthdate, so only the stored-compute variant is the
re-introduction these tests guard against.
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