canonical / canonical/test_observer

Start test returns 500 for duplicate image SHA

Open
#626 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
13
Forks
13
Avg merge
1d 2h
Merged PRs (30d)
11

Description

This start test request with an empty SHA (another image with the same SHA (empty) already must exist).
```
{
"family": "image",
"name": "cypress-noble-classic_desktop-arm64",
"version": "20260309",
"arch": "arm64",
"os": "ubuntu",
"release": "noble",
"owner": "cypress",
"execution_stage": "pending",
"image_url": "https://tel-image-cache.canonical.com/oem-share/cypress/images/noble-desktop-arm64+nvidia-latest.iso",
"sha256": "",
"test_plan": "com.canonical.certification::client-cert-desktop-24-04-automated",
"ci_link": "https://github.com/canonical/cypress-image-definitions/actions/runs/22864829317",
"environment": "202511-38084",
"needs_assignment": false
}
```
Causes `500` and this exception:
```
2026-03-10T13:37:27.980Z [test-observer-api] INFO: 10.86.58.1:51554 - "PUT /v1/test-executions/start-test HTTP/1.1" 500 Internal Server Error
2026-03-10T13:37:27.995Z [test-observer-api] ERROR: Exception in ASGI application
2026-03-10T13:37:27.995Z [test-observer-api] Traceback (most recent call last):
2026-03-10T13:37:27.995Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/pg8000/legacy.py", line 254, in execute
2026-03-10T13:37:27.995Z [test-observer-api] self._context = self._c.execute_unnamed(
2026-03-10T13:37:27.995Z [test-observer-api] ^^^^^^^^^^^^^^^^^^^^^^^^
2026-03-10T13:37:27.995Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/pg8000/core.py", line 715, in execute_unnamed
2026-03-10T13:37:27.995Z [test-observer-api] self.handle_messages(context)
2026-03-10T13:37:27.995Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/pg8000/core.py", line 835, in handle_messages
2026-03-10T13:37:27.995Z [test-observer-api] raise context.error
2026-03-10T13:37:27.995Z [test-observer-api] pg8000.exceptions.DatabaseError: {'S': 'ERROR', 'V': 'ERROR', 'C': '23505', 'M': 'duplicate key value violates unique constraint "unique_image"', 'D': 'Key (sha256)=() already exists.', 's': 'public', 't': 'artefact', 'n': 'unique_image', 'F': 'nbtinsert.c', 'L': '663', 'R': '_bt_check_unique'}
2026-03-10T13:37:27.995Z [test-observer-api]
2026-03-10T13:37:27.995Z [test-observer-api] During handling of the above exception, another exception occurred:
2026-03-10T13:37:27.995Z [test-observer-api]
2026-03-10T13:37:27.995Z [test-observer-api] Traceback (most recent call last):
2026-03-10T13:37:27.995Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
2026-03-10T13:37:27.995Z [test-observer-api] self.dialect.do_execute(
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 945, in do_execute
2026-03-10T13:37:27.996Z [test-observer-api] cursor.execute(statement, parameters)
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/pg8000/legacy.py", line 281, in execute
2026-03-10T13:37:27.996Z [test-observer-api] raise cls(msg)
2026-03-10T13:37:27.996Z [test-observer-api] pg8000.dbapi.IntegrityError: {'S': 'ERROR', 'V': 'ERROR', 'C': '23505', 'M': 'duplicate key value violates unique constraint "unique_image"', 'D': 'Key (sha256)=() already exists.', 's': 'public', 't': 'artefact', 'n': 'unique_image', 'F': 'nbtinsert.c', 'L': '663', 'R': '_bt_check_unique'}
2026-03-10T13:37:27.996Z [test-observer-api]
2026-03-10T13:37:27.996Z [test-observer-api] The above exception was the direct cause of the following exception:
2026-03-10T13:37:27.996Z [test-observer-api]
2026-03-10T13:37:27.996Z [test-observer-api] Traceback (most recent call last):
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 4449, in _flush
2026-03-10T13:37:27.996Z [test-observer-api] flush_context.execute()
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 466, in execute
2026-03-10T13:37:27.996Z [test-observer-api] rec.execute(self)
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/unitofwork.py", line 642, in execute
2026-03-10T13:37:27.996Z [test-observer-api] util.preloaded.orm_persistence.save_obj(
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 93, in save_obj
2026-03-10T13:37:27.996Z [test-observer-api] _emit_insert_statements(
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/orm/persistence.py", line 1233, in _emit_insert_statements
2026-03-10T13:37:27.996Z [test-observer-api] result = connection.execute(
2026-03-10T13:37:27.996Z [test-observer-api] ^^^^^^^^^^^^^^^^^^^
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
2026-03-10T13:37:27.996Z [test-observer-api] return meth(
2026-03-10T13:37:27.996Z [test-observer-api] ^^^^^
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 523, in _execute_on_connection
2026-03-10T13:37:27.996Z [test-observer-api] return connection._execute_clauseelement(
2026-03-10T13:37:27.996Z [test-observer-api] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1638, in _execute_clauseelement
2026-03-10T13:37:27.996Z [test-observer-api] ret = self._execute_context(
2026-03-10T13:37:27.996Z [test-observer-api] ^^^^^^^^^^^^^^^^^^^^^^
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1843, in _execute_context
2026-03-10T13:37:27.996Z [test-observer-api] return self._exec_single_context(
2026-03-10T13:37:27.996Z [test-observer-api] ^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
2026-03-10T13:37:27.996Z [test-observer-api] self._handle_dbapi_exception(
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2352, in _handle_dbapi_exception
2026-03-10T13:37:27.996Z [test-observer-api] raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
2026-03-10T13:37:27.996Z [test-observer-api] self.dialect.do_execute(
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 945, in do_execute
2026-03-10T13:37:27.996Z [test-observer-api] cursor.execute(statement, parameters)
2026-03-10T13:37:27.996Z [test-observer-api] File "/home/app/.venv/lib/python3.12/site-packages/pg8000/legacy.py", line 281, in execute
2026-03-10T13:37:27.996Z [test-observer-api] raise cls(msg)
2026-03-10T13:37:27.996Z [test-observer-api] sqlalchemy.exc.IntegrityError: (pg8000.dbapi.IntegrityError) {'S': 'ERROR', 'V': 'ERROR', 'C': '23505', 'M': 'duplicate key value violates unique constraint "unique_image"', 'D': 'Key (sha256)=() already exists.', 's': 'public', 't': 'artefact', 'n': 'unique_image', 'F': 'nbtinsert.c', 'L': '663', 'R': '_bt_check_unique'}
2026-03-10T13:37:27.996Z [test-observer-api] [SQL: /* Origin: repository.py:get_or_create */ INSERT INTO artefact (name, version, stage, family, due_date, bug_link, status, archived, comment, store, track, branch, series, repo, source, os, release, sha256, owner, image_url, assignee_id, created_at, updated_at) VALUES (%s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s, %s::DATE, %s::VARCHAR, %s, %s::BOOLEAN, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::VARCHAR, %s::INTEGER, now(), now()) RETURNING artefact.id, artefact.created_at, artefact.updated_at]
2026-03-10T13:37:27.996Z [test-observer-api] [parameters: ('cypress-noble-classic_desktop-arm64', '20260309', , 'image', None, '', 'UNDECIDED', False, '', '', '', '', '', '', '', 'ubuntu', 'noble', '', 'cypress', 'https://tel-image-cache.canonical.com/oem-share/cypress/images/noble-desktop-arm64+nvidia-latest.iso', None)]
2026-03-10T13:37:27.996Z [test-observer-api] (Background on this error at: https://sqlalche.me/e/20/gkpj)
```

In addition to handling that exception better, the curious thing is that shouldn't you be able to start multiple tests for the image with the same SHA? Needs investigation.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.