Skip to content

gen-sqlvalidation rules: not inherited, lost on abstract classes and mixins, value_presence unsupported #44

Open

Description

@jdsika

What

On upstream main 5aa87ad, gen-sqlvalidation:

  • checks only a class's own rules;
  • skips rules declared on abstract classes and mixins;
  • doesn't translate value_presence.

Reproduction

id: https://example.org/x
name: x
prefixes: {linkml: https://w3id.org/linkml/, ex: https://example.org/}
default_prefix: ex
default_range: string
imports: [linkml:types]
classes:
  P:
    # abstract: true   (or mixin: true with C: {mixins: [P]})
    attributes: {guard: {}, kind: {}, target: {}}
    rules:
      - preconditions: {slot_conditions: {guard: {equals_string: g}}}
        postconditions: {slot_conditions: {target: {equals_string: x}}}
  C: {is_a: P}

Run gen-sqlvalidation --no-include-comments schema.yaml, then run the output on SQLite tables created with gen-sqltables.

  1. Concrete P: there is only a FROM "P" rule query, so row C(guard='g', target='y') is not reported.
  2. Abstract or mixin P: there is no rule query at all, although tables P and C exist.
  3. Precondition guard: {value_presence: PRESENT}: the rule is skipped with "preconditions exist but produced no SQL conditions".
  4. Precondition {guard: {value_presence: ABSENT}, kind: {equals_string: k}}: the query is WHERE kind = 'k' AND (target != 'x' OR target IS NULL), with no warning. A row with guard set is reported, which is a false positive.

References

Proposed fix

  • For every non-abstract, non-mixin class, collect rules from class_ancestors(class_name) (mixins included), and translate them against that class's table and columns.
  • Translate value_presence: PRESENT / ABSENT as IS NOT NULL / IS NULL, negated in postconditions.
  • When any condition can't be translated, skip the rule with a warning instead of dropping that condition.

Acceptance criteria

SQLite-executed tests cover:

  • the concrete-parent, abstract-parent and mixin cases;
  • value_presence in both pre- and postconditions;
  • a mixed precondition with an untranslatable operator.

Activity

  1. changed the title [-]gen-sqlvalidation rules: not inherited, lost on abstract classes, value_presence preconditions unsupported[/-] [+]gen-sqlvalidation rules: not inherited, lost on abstract classes and mixins, value_presence unsupported[/+] on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions