Skip to content

Commit

Permalink
Support nested JSON in metadata.json, closes #2403
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 21, 2024
1 parent 1f3fb5f commit 9028d7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ async def apply_metadata_json(self):
for key in self._metadata_local or {}:
if key == "databases":
continue
await self.set_instance_metadata(key, self._metadata_local[key])
value = self._metadata_local[key]
if not isinstance(value, str):
value = json.dumps(value)
await self.set_instance_metadata(key, value)

# step 2: database-level metadata
for dbname, db in self._metadata_local.get("databases", {}).items():
Expand Down
7 changes: 5 additions & 2 deletions tests/test_internals_datasette.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,16 @@ async def test_apply_metadata_json():
"legislators": {
"tables": {"offices": {"summary": "office address or sumtin"}},
"queries": {
"millenntial_represetatives": {
"millennial_representatives": {
"summary": "Social media accounts for current legislators"
}
},
}
}
},
"weird_instance_value": {"nested": [1, 2, 3]},
},
)
await ds.invoke_startup()
assert (await ds.client.get("/")).status_code == 200
value = (await ds.get_instance_metadata()).get("weird_instance_value")
assert value == '{"nested": [1, 2, 3]}'

0 comments on commit 9028d7f

Please sign in to comment.