Skip to content

Commit 549e733

Browse files
authored
Merge pull request #356 from appwrite/fix/python-sdk-model-access
Fix Python templates for Appwrite SDK 23 models
2 parents d3e497f + 094466c commit 549e733

14 files changed

Lines changed: 40 additions & 30 deletions

File tree

.github/workflows/audit.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
sdk: stable
142142
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
143143
with:
144-
go-version: "1.26.5"
144+
go-version: "1.26.6"
145145
- name: Install OSV Scanner
146146
run: go install github.com/google/osv-scanner/v2/cmd/osv-scanner@${{ env.OSV_SCANNER_VERSION }}
147147
- name: Audit Dart templates
@@ -167,7 +167,7 @@ jobs:
167167
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
168168
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
169169
with:
170-
go-version: "1.26.5"
170+
go-version: "1.26.6"
171171
cache: false
172172
- name: Install govulncheck
173173
run: go install golang.org/x/vuln/cmd/govulncheck@v1.1.4
@@ -247,7 +247,7 @@ jobs:
247247
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
248248
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
249249
with:
250-
go-version: "1.26.5"
250+
go-version: "1.26.6"
251251
- name: Install OSV Scanner
252252
run: go install github.com/google/osv-scanner/v2/cmd/osv-scanner@${{ env.OSV_SCANNER_VERSION }}
253253
- name: Audit Maven coordinates in deps.gradle

python-ml/starter/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
appwrite
1+
appwrite==23.0.0
22
numpy

python-ml/starter/src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def main(context):
1212
Client()
1313
.set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"])
1414
.set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
15-
.set_key(context.req.headers["x-appwrite-key"])
15+
.set_key(context.req.headers.get("x-appwrite-key", ""))
1616
)
1717
users = Users(client)
1818

1919
try:
2020
response = users.list()
2121
# Log messages and errors to the Appwrite Console
2222
# These logs won't be seen by your end users
23-
context.log("Total users: " + str(response["total"]))
23+
context.log("Total users: " + str(response.total))
2424
except AppwriteException as err:
2525
context.error("Could not list users: " + repr(err))
2626

python/starter/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
appwrite
1+
appwrite==23.0.0

python/starter/src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def main(context):
1111
Client()
1212
.set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"])
1313
.set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
14-
.set_key(context.req.headers["x-appwrite-key"])
14+
.set_key(context.req.headers.get("x-appwrite-key", ""))
1515
)
1616
users = Users(client)
1717

1818
try:
1919
response = users.list()
2020
# Log messages and errors to the Appwrite Console
2121
# These logs won't be seen by your end users
22-
context.log("Total users: " + str(response["total"]))
22+
context.log("Total users: " + str(response.total))
2323
except AppwriteException as err:
2424
context.error("Could not list users: " + repr(err))
2525

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
appwrite
1+
appwrite==23.0.0

python/storage-cleaner/src/appwrite_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,22 @@ def clean_bucket(self, bucket_id: str):
4646
raise RuntimeError(
4747
f"Failed to list files from bucket {bucket_id}: {str(e)}"
4848
) from e
49-
files = response.get("files", [])
49+
files = response.files
5050

5151
if not files:
5252
break
5353

5454
batch_failed = False
5555
with ThreadPoolExecutor() as executor:
5656
future_to_file = {
57-
executor.submit(self.storage.delete_file, bucket_id, f.get("$id")): f
57+
executor.submit(self.storage.delete_file, bucket_id, f.id): f
5858
for f in files
59-
if f.get("$id")
59+
if f.id
6060
}
6161

6262
for future in as_completed(future_to_file):
6363
file_info = future_to_file[future]
64-
file_id = file_info.get("$id")
64+
file_id = file_info.id
6565
try:
6666
future.result()
6767
deleted_files_count += 1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
appwrite
1+
appwrite==23.0.0
22
algoliasearch

python/sync_with_algolia/src/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from algoliasearch.search_client import SearchClient
33
from appwrite.client import Client
4+
from appwrite.models import Document
45
from appwrite.services.databases import Databases
56
from appwrite.query import Query
67
from .utils import get_static_file, throw_if_missing, interpolate
@@ -55,16 +56,19 @@ def main(context):
5556
queries,
5657
)
5758

58-
if len(response.documents) > 0:
59-
cursor = response.documents[len(response.documents) - 1]["$id"]
59+
documents: list[Document] = response.documents
60+
61+
if len(documents) > 0:
62+
cursor = documents[-1].id
6063
else:
6164
context.log("No more documents found.")
6265
cursor = None
6366
break
6467

65-
context.log(f"Syncing chunk of {len(response.documents)} documents...")
68+
context.log(f"Syncing chunk of {len(documents)} documents...")
6669
documents_with_object_ids = [
67-
{"objectID": document["$id"], **document} for document in response.documents
70+
{"objectID": document.id, "$id": document.id, **document.data}
71+
for document in documents
6872
]
6973
index.save_objects(documents_with_object_ids)
7074

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
appwrite
1+
appwrite==23.0.0
22
meilisearch

0 commit comments

Comments
 (0)