All jobs

Fix "The Default Datetime Adapter Is Deprecated as of Python 3.12" in a sqlite3 App

Yes. An agent moves the app to Python 3.12, reproduces both sqlite3 warnings, registers an adapter and converter that keep the stored format and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and finds where datetimes cross into SQLite. In a Flask service like OxOOo/ProxyPoolWithUI, a proxy pool with a web UI, the Dockerfile starts FROM python:3.7.0, the README asks for Python 3.6 or newer, and main.py runs three processes: a fetcher, a validator and the API. db/conn.py opens the database at line 14 with sqlite3.connect(DATABASE_PATH, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES), and the tables in db/Proxy.py and db/Fetcher.py declare validate_date TIMESTAMP, to_validate_date TIMESTAMP NOT NULL and last_fetch_date TIMESTAMP. datetime.datetime.now() goes in as a bound parameter at conn.py lines 53, 73, 79 and 266 and is set on model objects at Proxy.py lines 42, 100, 107 and 112, so every insert, update and the SELECT count(*) FROM proxies WHERE to_validate_date<=? poll depend on the default adapter, and every read of a TIMESTAMP column depends on the default converter.

Then it reproduces the warnings with the app's own schema. In a Python 3.12 environment with -W default, the count query with a datetime parameter prints DeprecationWarning: The default datetime adapter is deprecated as of Python 3.12, an insert through the same path prints it again, and reading validate_date back prints DeprecationWarning: The default timestamp converter is deprecated as of Python 3.12. The same script on 3.11 prints nothing. The warnings fire on every poll of the validator loop, so a container moved to the 3.12 image fills its logs with them until the defaults are removed.

The fix keeps the on-disk format. The agent adds two lines next to the sqlite3 import in db/conn.py: sqlite3.register_adapter(datetime.datetime, lambda v: v.isoformat(" ")) and sqlite3.register_converter("timestamp", lambda b: datetime.datetime.fromisoformat(b.decode())). The default adapter wrote the ISO text with a space separator, YYYY-MM-DD HH:MM:SS.ffffff, and isoformat(" ") writes exactly that, so rows written by the old code still parse through the new converter, and fromisoformat reads both the six-digit and the no-microsecond spelling. A TIMESTAMP column matches the converter by name case-insensitively, which is why it is registered as timestamp.

It proves the change under the strictest setting. The same script runs again on 3.12 with -W error::DeprecationWarning: the count query, the insert and the read all succeed, the read returns datetime.datetime objects with their microseconds, and the temporary row is deleted. On 3.11 the script is unchanged and silent, so the fix can ship before the base image moves. The Dockerfile line becomes FROM python:3.12, and the pull request notes that the pinned requirements.txt, Flask 1.1.2 and lxml 4.6.2, is the next thing to revisit on that image.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "We are moving this service to Python 3.12 and its logs fill with \"DeprecationWarning: The default datetime adapter is deprecated as of Python 3.12\". Read the Dockerfile, the database module and every file that passes a datetime to sqlite3 or declares a TIMESTAMP column first. Reproduce the adapter and converter warnings on 3.12 with the app's own schema and quote them. Register an adapter and a converter that write and read the exact text format the defaults used, so existing rows keep parsing, and show the same operations passing on 3.12 with DeprecationWarning turned into an error and still passing on 3.11. Move the Dockerfile base image to 3.12. Open a pull request that quotes the before and after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request touching db/conn.py and the Dockerfile: the adapter and converter registered beside the connection, with a comment naming the Python 3.12 deprecation they replace, and the base image moved to 3.12. The description quotes both warnings from the 3.12 run, the same insert, count and read passing with -W error::DeprecationWarning, and the stored text for one row, so a reviewer can see it is the format the old code wrote.

A reviewer checks the format argument of isoformat, since a T separator would still parse but would change what ORDER BY and <= compare against older rows, and that the converter name matches the column's declared type. The run's record holds each script run with its output, on 3.11 and 3.12, so the before and after can be opened rather than taken on trust.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run moves the base image to the current Python, runs the app's database paths with warnings as errors and opens one pull request on its own branch; a week where a deprecation has no replacement the agent can prove ends needs_review with the warning attached, and a week already on the current image opens nothing.

The same body works from your own code with POST /o/{org}/sessions and an API key when a dependency bot's base image bump turns red; the key's webhook_url receives run.completed or run.failed with the session URL and the pull request when the run ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A warning that only appears on the new interpreter is easy to ship and hard to see: the app keeps working on 3.12, and the message shows up in a container log at the rate of the validator loop. The agent runs the app's own insert, poll and read on 3.11 and 3.12 in its sandbox, keeps every run and its output in the run's record, and the pull request shows the warnings going from two per operation to none with the warning category promoted to an error.

The fix is short but the format is a decision: a converter that reads what the old adapter wrote keeps every existing row readable, and a sortable text format keeps to_validate_date<=? correct across old and new rows. The agent writes the stored text out in the pull request so the reviewer checks the format, not the intention.

Frequently asked questions

Why did Python 3.12 deprecate the default adapter?

The built-in datetime adapter and timestamp converter were implicit, ignored time zones and had quirks the documentation could not fix without changing stored data, so 3.12 deprecates them and asks each application to register its own with the format it wants. Nothing changes at runtime yet beyond the warning.

Will my existing rows still read back?

Yes, when the adapter writes the same text the default did. The default adapter stored the ISO text with a space separator, 2026-11-10 09:23:34.958118, and isoformat(" ") produces exactly that; fromisoformat parses it, with or without microseconds. The agent prints a stored row in the pull request so you can confirm the format.

Does the converter also cover DATE columns?

Not by itself. A DATE column has its own deprecated default converter; if your schema declares one, the agent registers a date converter the same way and shows it in the same run. This app declares only TIMESTAMP columns.

Why change the Dockerfile in the same pull request?

Because the warning only exists on 3.12 and the registered functions are harmless on 3.11, the two changes are safe together, and the base image bump is what the run was asked to deliver. If you want the image bump separately, say so in the prompt.

More Python sqlite3 jobs

More jobs like this: Upgrade dependencies weekly

Keep reading