I don't think it is related to a null `sip` but rather a non-existing `maasserver_dnsresource` leading to an empty `domain.name`.
The only place where we have `sys_dns_dnsresource_ip_unlink` trigger is:
```
register_procedure(DNS_DNSRESOURCE_IP_UNLINK)
register_trigger(
"maasserver_dnsresource_ip_addresses",
"sys_dns_dnsresource_ip_unlink",
"delete",
)
```
And the only thing that might lead to the failure is a null value of `domain.name` (since `sip.ip` is guarded):
```
IF sip.ip IS NOT NULL THEN
PERFORM sys_dns_publish_update(
'ip ' || host(sip.ip) || ' unlinked from resource ' || COALESCE(resource.name, 'NULL') || ' on zone ' || domain.name);
END IF;
```
While `name` itself cannot be null according to the schema, the following query can produce no results, because `OLD.dnsresource_id` is pointing to `maasserver_dnsresource` that was removed:
```
SELECT maasserver_dnsresource.* INTO resource
FROM maasserver_dnsresource
WHERE maasserver_dnsresource.id = OLD.dnsresource_id;
SELECT maasserver_domain.* INTO domain
FROM maasserver_domain
WHERE maasserver_domain.id = resource.domain_id;
```
Bcause trigger is executed when we *delete* row from `maasserver_dnsresource_ip_addresses`, but there are no FK relation, so `maasserver_dnsresource_ip_addresses` might end up having an orphaned `dnsresource_id`
Here is an example orphaned row found in [0]
```
select *
from maasserver_dnsresource_ip_addresses t1
left join maasserver_dnsresource t2 on t1.dnsresource_id = t2.id
where t2.name is null;
id | dnsresource_id | staticipaddress_id | id | created | updated | name | domain_id | address_ttl
----+----------------+--------------------+----+---------+---------+------+-----------+-------------
12 | 8 | 27 | | | | | |
(1 row)
```
I don't think it is related to a null `sip` but rather a non-existing `maasserver_ dnsresource` leading to an empty `domain.name`.
The only place where we have `sys_dns_ dnsresource_ ip_unlink` trigger is: procedure( DNS_DNSRESOURCE _IP_UNLINK) _dnsresource_ ip_addresses" , dns_dnsresource _ip_unlink" ,
```
register_
register_trigger(
"maasserver
"sys_
"delete",
)
```
And the only thing that might lead to the failure is a null value of `domain.name` (since `sip.ip` is guarded): publish_ update(
COALESCE( resource. name, 'NULL') || ' on zone ' || domain.name);
```
IF sip.ip IS NOT NULL THEN
PERFORM sys_dns_
'ip ' || host(sip.ip) || ' unlinked from resource ' ||
END IF;
```
While `name` itself cannot be null according to the schema, the following query can produce no results, because `OLD.dnsresourc e_id` is pointing to `maasserver_ dnsresource` that was removed: dnsresource. * INTO resource dnsresource dnsresource. id = OLD.dnsresource_id; domain. id = resource.domain_id;
```
SELECT maasserver_
FROM maasserver_
WHERE maasserver_
SELECT maasserver_domain.* INTO domain
FROM maasserver_domain
WHERE maasserver_
```
Bcause trigger is executed when we *delete* row from `maasserver_ dnsresource_ ip_addresses` , but there are no FK relation, so `maasserver_ dnsresource_ ip_addresses` might end up having an orphaned `dnsresource_id`
Here is an example orphaned row found in [0] dnsresource_ ip_addresses t1 dnsresource t2 on t1.dnsresource_id = t2.id
```
select *
from maasserver_
left join maasserver_
where t2.name is null;
id | dnsresource_id | staticipaddress_id | id | created | updated | name | domain_id | address_ttl ------- ------- +------ ------- ------- +----+- ------- -+----- ----+-- ----+-- ------- --+---- ------- --
----+--
12 | 8 | 27 | | | | | |
(1 row)
```
[0] https:/ /solutions. qa.canonical. com/testruns/ 859d8396- 5fe0-4c85- 9fbd-26cce6ffde e7