1.7 beta duplicate key value violations

Upgraded from 1.6.1 to 1.7 beta. Immediately began getting syslog errors:
maas-apiserver[269061]: {“message”: “Failed to commit transaction due to (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class ‘asyncpg.exceptions.UniqueViolationError’>: duplicate key value violates unique constraint "maasserver_dnsresource_i_dnsresource_id_staticipa_4ae7b01e_uniq"\nDETAIL: Key (dnsresource_id, staticipaddress_id)=(91, 129) already exists.\n[SQL: INSERT INTO maasserver_dnsresource_ip_addresses (dnsresource_id, staticipaddress_id) VALUES ($1::BIGINT, $2::BIGINT) RETURNING maasserver_dnsresource_ip_addresses.id]\n[parameters: (91, 129)]\n(Background on this error at: https://sqlalche.me/e/20/gkpj)”, “taskName”: “starlette.middleware.base.BaseHTTPMiddleware.call..call_next..coro”, “context_id”: “14689de8-e980-41ef-9e2c-4ff1688afd5c”, “timestamp”: “2025-08-22T09:46:03.820014Z”, “logger”: “maasapiserver.common.middlewares.db:44”, “level”: “INFO”, “thread”: “MainThread:137004176322688”}

So I wiped the entire maas, postgresql and reinstalled. Again… same thing.
Anyone have a fix for this?

Hi @tosaraja
Are you really talking about 1.7 or maybe it is 3.7?
Can you please describe exact steps to reproduce

Yes, sorry. Tired after a long week it seems :smiley: 3.6.1 → 3.7 beta was what i meant.
The value of 91 seemed to be the entry of of one of the hosts that was connected. I just deleted it manually from the terminal (dnsresource delete 91), but i have tons of postgres problems still spamming the log.

Going through the steps on how to reproduce would take the better part of the day, since the whole system is set up with ansible which configures all subnets and, ip ranges etc. But with 3.7 beta I end up with tons of weird syslog problems. I can try listing them here or just mention a few:

maas-temporal-worker[1037283]: ; Communication with 0.0.0.30#53 failed: timed out
maas-temporal-worker[449331]: #033[2m2025-08-25T05:54:40.924041Z#033[0m #033[33m WARN#033[0m #033[2mtemporal_sdk_core::worker::activities#033[0m#033[2m:#033[0m Activity not found on completion. This may happen if the activity has already been cancelled but completed anyway. #033[3mtask_token#033[0m#033[2m=#033[0mTaskToken(long_token_edited) #033[3mdetails#033[0m#033[2m=#033[0mStatus { code: NotFound, message: “workflow execution already completed”, details: b"\x08\x05\x12$workflow execution already completed\x1aB\n@type.googleapis.com/temporal.api.errordetails.v1.NotFoundFailure", metadata: MetadataMap { headers: {“content-type”: “application/grpc”} }, source: None }
maas-temporal-worker[1037366]: ; Communication with 0.0.0.30#53 failed: timed out

regiond[449333]: maasserver.region_controller: [warn] The dynamic dns update notification ‘’ is not valid. It will be dropped.

Was ^ due to Bug #2062107 “Failed to reload DNS; serial mismatch on domains m...” : Bugs : MAAS ?

maas-temporal-worker[1038424]: ; Communication with 0.0.0.30#53 failed: timed out
maas-temporal-worker[449331]: {“message”: “Completing activity as failed ({‘activity_id’: ‘4’, ‘activity_type’: ‘check-serial-update’, ‘attempt’: 1, ‘namespace’: ‘default’, ‘task_queue’: ‘region:ffnkfs’, ‘workflow_id’: ‘configure-dns’, ‘workflow_run_id’: ‘0cac9542-a4bd-47ab-abfa-8e984342f83f’, ‘workflow_type’: ‘configure-dns’})”, “exc_info”: “Traceback (most recent call last):\n File "/usr/lib/python3/dist-packages/temporalio/worker/_activity.py", line 453, in _run_activity\n result = await impl.execute_activity(input)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/usr/lib/python3/dist-packages/temporalio/worker/_activity.py", line 711, in execute_activity\n return await input.fn(*input.args)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/usr/lib/python3/dist-packages/maastemporalworker/workflow/dns.py", line 970, in check_serial_update\n assert soa.serial == serial.serial\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAssertionError”, “taskName”: “Task-123137”, “temporal_activity”: {“activity_id”: “4”, “activity_type”: “check-serial-update”, “attempt”: 1, “namespace”: “default”, “task_queue”: “region:ffnkfs”, “workflow_id”: “configure-dns”, “workflow_run_id”: “0cac9542-a4bd-47ab-abfa-8e984342f83f”, “workflow_type”: “configure-dns”}, “logger”: “temporalio.activity:493”, “level”: “WARNING”, “thread”: “MainThread:131664525160576”, “timestamp”: “2025-08-25T06:00:21.071713Z”}

And then we have the usual DNS problems. Trying to re-deploy a host gets me this log. But I can’t delete the entry from the GUI since the entry is greyed out, so I have to use the cli to delete it. But that ends up with the GUI and database not being in sync. Also see Bug #2055691 “MAAS 3.3.5 keeps “forgetting” DNS entries” : Bugs : MAAS

maas-apiserver[449901]: {“message”: “Start processing request”, “taskName”: “Task-268118”, “request_method”: “POST”, “request_path”: “/MAAS/a/v3internal/leases”, “request_query”: “”, “request_remote_ip”: null, “context_id”: “f218ef0e-6f93-4f98-9385-91910c255fcc”, “timestamp”: “2025-08-25T06:59:35.972977Z”, “logger”: “maasapiserver.v3.middlewares.context:34”, “level”: “INFO”, “thread”: “MainThread:139058764198016”}
maas-apiserver[449901]: {“message”: “Lease update: expiry for 10.xxx.xxx.xxx on xx:xx:xx:xx:xx:xx at 2025-08-25 06:44:19 (lease time: 0s)”, “taskName”: “starlette.middleware.base.BaseHTTPMiddleware.call..call_next..coro”, “context_id”: “f218ef0e-6f93-4f98-9385-91910c255fcc”, “timestamp”: “2025-08-25T06:59:35.978719Z”, “logger”: “maasservicelayer.services.leases:82”, “level”: “INFO”, “thread”: “MainThread:139058764198016”}
maas-apiserver[449901]: {“message”: “Failed to commit transaction due to (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class ‘asyncpg.exceptions.UniqueViolationError’>: duplicate key value violates unique constraint "maasserver_dnsresource_i_dnsresource_id_staticipa_4ae7b01e_uniq"\nDETAIL: Key (dnsresource_id, staticipaddress_id)=(68, 858369) already exists.\n[SQL: INSERT INTO maasserver_dnsresource_ip_addresses (dnsresource_id, staticipaddress_id) VALUES ($1::BIGINT, $2::BIGINT) RETURNING maasserver_dnsresource_ip_addresses.id]\n[parameters: (68, 858369)]\n(Background on this error at: https://sqlalche.me/e/20/gkpj)”, “taskName”: “starlette.middleware.base.BaseHTTPMiddleware.call..call_next..coro”, “context_id”: “f218ef0e-6f93-4f98-9385-91910c255fcc”, “timestamp”: “2025-08-25T06:59:36.004407Z”, “logger”: “maasapiserver.common.middlewares.db:44”, “level”: “INFO”, “thread”: “MainThread:139058764198016”}
maas-apiserver[449901]: {“message”: “End processing request”, “taskName”: “Task-268118”, “status_code”: 422, “elapsed_time_seconds”: 0.032097578048706055, “context_id”: “f218ef0e-6f93-4f98-9385-91910c255fcc”, “timestamp”: “2025-08-25T06:59:36.005021Z”, “logger”: “maasapiserver.v3.middlewares.context:43”, “level”: “INFO”, “thread”: “MainThread:139058764198016”}

Those ID numbers are well above 1 million now and keep rising. Yet, when I go into postgresql, there are no such entries present. I have no clue what these “duplicates” are, since they aren’t duplicate with anything.

maas-apiserver[449901]: {“message”: “Failed to commit transaction due to (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class ‘asyncpg.exceptions.UniqueViolationError’>: duplicate key value violates unique constraint "maasserver_dnsresource_i_dnsresource_id_staticipa_4ae7b01e_uniq"\nDETAIL: Key (dnsresource_id, staticipaddress_id)=(1067718, 887210) already exists.\n[SQL: INSERT INTO maasserver_dnsresource_ip_addresses (dnsresource_id, staticipaddress_id) VALUES ($1::BIGINT, $2::BIGINT) RETURNING maasserver_dnsresource_ip_addresses.id]\n[parameters: (1067718, 887210)]\n(Background on this error at: https://sqlalche.me/e/20/gkpj)”, “taskName”: “starlette.middleware.base.BaseHTTPMiddleware.call..call_next..coro”, “context_id”: “99cb8099-f035-4f52-a890-25aad8fa7615”, “timestamp”: “2025-08-25T11:28:53.944904Z”, “logger”: “maasapiserver.common.middlewares.db:44”, “level”: “INFO”, “thread”: “MainThread:139058764198016”}