# `data.rule_erased_field`

A rule across an entity's fields reads a field that erasure or retention clears, so erasing a person could break it.

Area 15, [Personal data](/docs/personal-data.md); not declinable; the next step is usually the agent's.

## Why Jadpo refuses it

A rule across an entity's fields holds for every record stored, whichever
write stores it. Erasure and retention change records without any write
of yours: erasing a person clears what was theirs on the records it
keeps, and a field's `retention:` clears its value once its time is up.
Erasing a person must always succeed, so neither may break a rule, and a
rule may not read a field either of them clears.

Here a visitor's `signup_ip` is cleared 30 days after they sign up, and
the rule says a visitor always has one.

## What it looks like

main.jadpo:

```jadpo
config {
    signup_ip_kept: Duration {
        default: 30d
    }
}

entity Visitor {
    id: Uuid
    signup_ip: IpAddress? {
        retention: {
            after: config.signup_ip_kept
            since: created_at
        }
    }
    created_at: Instant {
        generated: Generated.on_create
    }

    rule known: match signup_ip {
        none -> false
        some(ip) -> true
    }
}
```

```text
error: The rule `Visitor.known` reads `signup_ip`, which erasure or retention clears
 --> main.jadpo:19:10
   |
19 |     rule known: match signup_ip {
   |          ^^^^^ reads `signup_ip`
  reason: `Visitor.signup_ip` is cleared without any write of yours, since its `retention:` clears it once its time is up, and that must always succeed, so no rule may be broken by it: a rule across an entity's fields reads only fields erasure and retention leave as they are.
  next: Check `signup_ip` where it is written, in the `Input` the write takes, rather than in a rule on `Visitor` (agent)
  rule: data.rule_erased_field
  help: https://jadpo.dev/docs/errors/data.rule_erased_field

check failed: 1 error, 1 file
```

`(agent)` at the end of the `next:` line means your coding agent can make
the fix itself.

## How to fix it

**If a visitor must give an address when they sign up**, check it where
it is written instead, on the `Input` a route takes, so a request without
one is refused before anything runs, and let the stored record lose it
when its time is up. `main.jadpo` becomes:

```jadpo
config {
    signup_ip_kept: Duration {
        default: 30d
    }
}

entity Visitor {
    id: Uuid
    signup_ip: IpAddress? {
        retention: {
            after: config.signup_ip_kept
            since: created_at
        }
    }
    created_at: Instant {
        generated: Generated.on_create
    }
}

type SignUp = Input {
    signup_ip: IpAddress
}
```

`SignUp` has to hold an address, and a stored visitor's goes after 30
days.

## Related

- [Rules across an entity's fields](/docs/fields-and-their-settings.md#rules-across-an-entitys-fields)
- [What erasure reaches](/docs/erasure-after-the-commit.md#what-erasure-reaches)
- [Retention](/docs/retention.md)
