[BUG](system) Model constraints from multiple constrained bases are dropped

Open
#806 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
json, python
Domain
backend

Research direction

Start by reading ModelConstraint.get_model_constraints and the forbid_if decorator, then trace how constrained base classes contribute validators and schema constraints during multiple inheritance. Check the related fixes in #784 and #785 for the single inheritance behavior. Done means constraints from both A and B appear in the model constraint list and are enforced when constructing C.

Written by the indexing model from the issue text.

Description

When a model inherits from two bases that both carry model constraints (class C(A, B)), the second base's constraints are lost:

  • The model's constraint list comes only from the first base, so JSON Schema and PySpark miss the second base's rules.
  • When both bases use the same constraint kind, Pydantic also enforces only one of them, because the validator names collide.
@forbid_if(["bar"], FieldEqCondition("foo", "a"))
class A(Base): ...

@forbid_if(["baz"], FieldEqCondition("foo", "b"))
class B(Base): ...

class C(A, B): ...

ModelConstraint.get_model_constraints(C)  # only A's constraint
C(foo="b", baz=1)                          # accepted

No schema model does this today.

Related: #784 / #785, which fix the single-inheritance case. And mentioned this potential issue.

Dominant language
Python
Stars
219
Forks
20
Avg merge
1d 21h
Merged PRs (30d)
37

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OvertureMaps/schema

All issues in OvertureMaps/schema

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.