Skip to content

Conversation

samhotep
Copy link
Member

@samhotep samhotep commented Sep 26, 2025

Done

  • Split the database sessions by engines, and subsequently, by database URLs. This means the application can communicate with different replicas simultaneously, with independent connections.
  • Required an explicit call select_session("primary") to access the main database session. This should be reserved for upsert actions. Otherwise, using the default db will connect to a replica instead.

QA

  • Check out this feature branch
  • Start different databases on different ports, and update the .env file to point to these replicas
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres
docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=postgres postgres
docker run -d -p 5434:5432 -e POSTGRES_PASSWORD=postgres postgres
  • Run the site using the command ./run serve
  • View the site locally in your web browser at: http://0.0.0.0:8030/
  • In the root folder, try to upload a CVE with
python3 scripts/create-cves.py --host http://0.0.0.0:8103 scripts/payloads/cves.json 

Issue / Card

Fixes WD-26253

[if relevant, include a screenshot]

@samhotep samhotep changed the title Wd 26253 split security api database url into replicas Wd 26253 split security api database url into replica urls Sep 26, 2025
@muhammad-ali-pk
Copy link

@samhotep Spent quite some time trying to run the project with ./run serve, but ran into python version issues. Even using conda with specific python version environments didn't work.

Switched to using dotrun as suggested in the project's README, and ran the project.

Got gin extension errors first. Worth mentioning in QA to create pg_trm extension on the postgres instance first, like so

CREATE EXTENSION IF NOT EXISTS pg_trgm;

Then I ran the python command specified in QA

python3 scripts/create-cves.py --host http://0.0.0.0:8103 scripts/payloads/cves.json

Running the specified command fails with

requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=8103): Max retries exceeded with url: /security/updates/cves.json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7c1c38b263b0>: Failed to establish a new connection: [Errno 111] Connection refused'))```

Then ran the command with port 8030, as the project is running on 8030. It opens up juju charms login screen, then fails with this error

Traceback (most recent call last):
  File "/home/engr-ali/canonical/projects/ubuntu-com-security-api/scripts/create-cves.py", line 66, in <module>
    client.cookies.save(ignore_discard=True)
  File "/home/engr-ali/.pyenv/versions/3.10.17/lib/python3.10/http/cookiejar.py", line 2120, in save
    if cookie.has_nonstandard_attr(HTTPONLY_ATTR):
  File "/home/engr-ali/.pyenv/versions/3.10.17/lib/python3.10/http/cookiejar.py", line 805, in has_nonstandard_attr
    return name in self._rest
TypeError: argument of type 'NoneType' is not iterable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants