Skip to content

Commit 744fe72

Browse files
authored
Merge pull request #22 from cloudblue/fix/LITE-27244
LITE-27244 Removed limit of returned DB objects in DB List API
2 parents 93ffed7 + ae39b42 commit 744fe72

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
* Added server errors handling
2323
* Added workload description and external link to docs
2424
* 0.3.2: Backend dependencies are bumped
25+
* 0.3.3: Removed limit of returned DB objects in DB List API

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM cloudblueconnect/connect-extension-runner:27.19
1+
FROM cloudblueconnect/connect-extension-runner:27.21
22

33
COPY pyproject.toml /install_temp/.
44
COPY poetry.* /install_temp/.

dbaas/extension.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "DBaaS",
33
"description": "On-demand provisioning of cloud-based database storages as a service.",
4-
"version": "0.3.2",
4+
"version": "0.3.3",
55
"audience": ["reseller", "distributor", "vendor"],
6-
"readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.2/README.md",
7-
"changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.2/CHANGELOG.md",
6+
"readme_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/README.md",
7+
"changelog_url": "https://github.com/cloudblue/connect-extension-dbaas/blob/0.3.3/CHANGELOG.md",
88
"icon": "googleExtensionBaseline"
99
}

dbaas/services.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
class DB:
3535
COLLECTION = Collections.DB
3636
MAX_ID_GENERATION_RETRIES = 3
37+
LIST_STEP_LENGTH = 20
3738

3839
@classmethod
3940
async def list(cls, db: AsyncIOMotorDatabase, context: Context) -> list[dict]:
@@ -43,9 +44,14 @@ async def list(cls, db: AsyncIOMotorDatabase, context: Context) -> list[dict]:
4344
).sort('events.created.at', pymongo.DESCENDING)
4445

4546
results = []
46-
for db_document in await cursor.to_list(length=20):
47-
doc = cls._db_document_repr(db_document)
48-
results.append(doc)
47+
48+
docs = await cursor.to_list(length=cls.LIST_STEP_LENGTH)
49+
while docs:
50+
for db_document in docs:
51+
doc = cls._db_document_repr(db_document)
52+
results.append(doc)
53+
54+
docs = await cursor.to_list(length=cls.LIST_STEP_LENGTH)
4955

5056
return results
5157

poetry.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/services/test_db.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ async def test_list_several_account_dbs(db, admin_context):
101101
assert [r['id'] for r in results] == [db['id'] for db in (db3, db2, other_account_db, db1)]
102102

103103

104+
@pytest.mark.asyncio
105+
async def test_list_number_of_dbs_gt_than_cursor_length(db):
106+
account_id = 'PA-456'
107+
108+
dbs = DBFactory.create_batch(size=25, account_id=account_id)
109+
await db[Collections.DB].insert_many(dbs)
110+
111+
results = await DB.list(db, Context(account_id=account_id))
112+
assert len(results) == 25
113+
assert len({r['id'] for r in results}) == 25
114+
115+
104116
@pytest.mark.asyncio
105117
async def test_retrieve_is_empty(db):
106118
result = await DB.retrieve('any', db, Context(account_id='VA-123-456'))

0 commit comments

Comments
 (0)