Skip to content

Commit

Permalink
Special treatment for sql, _redirect_to, _title
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 4, 2024
1 parent bd00ae1 commit d3115d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions datasette_write/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ async def inner():
"database": database,
}
for column in columns:
field_name = column["name"]
current_value = str(row_dict.get(field_name) or "")
column_name = column["name"]
field_name = column_name
if column_name in ("sql", "_redirect_to", "_title"):
field_name = "_{}".format(column_name)
current_value = str(row_dict.get(column_name) or "")
if "\n" in current_value:
field_name = field_name + "_textarea"
if column["notnull"]:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def ds(tmp_path_factory):
insert into simple_pk_multiline (id, name) values (1, 'one' || char(10) || 'two');
create table compound_pk (id1 integer, id2 integer, name text, primary key (id1, id2));
insert into compound_pk (id1, id2, name) values (1, 2, 'one-two');
create table has_not_null (id integer primary key, name text not null);
insert into has_not_null (id, name) values (1, 'one');
create table has_not_null (id integer primary key, sql text not null);
insert into has_not_null (id, sql) values (1, 'one');
"""
)
ds = Datasette([db_path, db_path2])
Expand Down Expand Up @@ -289,7 +289,7 @@ async def test_title(ds, scenario):
textwrap.dedent(
"""
update "has_not_null" set
"name" = :name
"sql" = :_sql
where "id" = :id_hidden
"""
).strip(),
Expand Down

0 comments on commit d3115d8

Please sign in to comment.