microsoft / microsoft/Qcodes

Make it possible to use AtomicConnection as a context manager

Open
#5,314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
459
Forks
359
Avg merge
3d 6h
Merged PRs (30d)
73

Description

**Updated** to reflect change in name of class

### Discussed in https://github.com/QCoDeS/Qcodes/discussions/5309

Originally posted by **lucas-hak** August 10, 2023
Hello, I am trying to make a ConnectionPlus to a database. I am then using this to open a dataset by its id.
```
import qcodes.dataset as ds
from qcodes.dataset.sqlite.database import connect
with connect(file_path) as db:
dataset = ds.load_by_id(ds_id, db)
```
However when I run this I get an error.
```
ValueError: atomic context manager only accepts ConnectionPlus database connection objects.
```
When investigating this error it seems that the variable `db` I have initialized is a sqlite3.Connection object and not a ConnectionPlus object.

Am I using the `connect `function wrong? I want to be able to initialize this in a way that it closes to reduce the chance of keeping my datasets. If someone has advice about how I should handle this that would be greatly appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the AtomicConnection and connect entry points referenced in the issue, then reproduce the shown ds.load_by_id example with a database connection. Check how the current atomic context manager validates connections and how connections are closed. Done means AtomicConnection can be used with with and the dataset lookup succeeds while the connection is closed afterward.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
database
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.