Skip to content

Commit

Permalink
Fix for params metadata error, closes #2455
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 9, 2025
1 parent 1902735 commit 34390bb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions datasette/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ async def favicon(request, send):
)


def _to_string(value):
if isinstance(value, str):
return value
else:
return json.dumps(value, default=str)


class Datasette:
# Message constants:
INFO = 1
Expand Down Expand Up @@ -451,23 +458,23 @@ async def apply_metadata_json(self):
if key == "databases":
continue
value = self._metadata_local[key]
if not isinstance(value, str):
value = json.dumps(value)
await self.set_instance_metadata(key, value)
await self.set_instance_metadata(key, _to_string(value))

# step 2: database-level metadata
for dbname, db in self._metadata_local.get("databases", {}).items():
for key, value in db.items():
if key in ("tables", "queries"):
continue
await self.set_database_metadata(dbname, key, value)
await self.set_database_metadata(dbname, key, _to_string(value))

# step 3: table-level metadata
for tablename, table in db.get("tables", {}).items():
for key, value in table.items():
if key == "columns":
continue
await self.set_resource_metadata(dbname, tablename, key, value)
await self.set_resource_metadata(
dbname, tablename, key, _to_string(value)
)

# step 4: column-level metadata (only descriptions in metadata.json)
for columnname, column_description in table.get("columns", {}).items():
Expand Down

0 comments on commit 34390bb

Please sign in to comment.