Skip to content

Commit 4885ef6

Browse files
committed
plugins/sql: pay attention to deprecated in schema.
For now, we ignore every deprecated field, but put in the logic so that future deprecations will work as expected. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e531904 commit 4885ef6

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

plugins/sql.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,14 +1138,35 @@ static void add_table_singleton(struct table_desc *td,
11381138
tal_arr_expand(&td->columns, col);
11391139
}
11401140

1141+
static bool is_deprecated(const jsmntok_t *deprecated_tok)
1142+
{
1143+
const char *deprstr;
1144+
1145+
if (!deprecated_tok)
1146+
return false;
1147+
1148+
/* If deprecated APIs are globally disabled, we don't want them! */
1149+
if (!deprecated_apis)
1150+
return true;
1151+
1152+
/* If it was deprecated before our release, we don't want it; older ones
1153+
* were simply 'deprecated: true' */
1154+
deprstr = json_strdup(tmpctx, schemas, deprecated_tok);
1155+
assert(strstarts(deprstr, "v"));
1156+
if (streq(deprstr, "v0.12.0") || streq(deprstr, "v23.02"))
1157+
return true;
1158+
1159+
return false;
1160+
}
1161+
11411162
static void add_table_properties(struct table_desc *td,
11421163
const jsmntok_t *properties)
11431164
{
11441165
const jsmntok_t *t;
11451166
size_t i;
11461167

11471168
json_for_each_obj(i, t, properties) {
1148-
const jsmntok_t *type;
1169+
const jsmntok_t *type, *deprecated_tok;
11491170
struct column col;
11501171

11511172
if (ignore_column(td, t))
@@ -1155,6 +1176,13 @@ static void add_table_properties(struct table_desc *td,
11551176
* another branch with actual types, so ignore this */
11561177
if (!type)
11571178
continue;
1179+
1180+
/* Depends on when it was deprecated, and whether deprecations
1181+
* are enabled! */
1182+
deprecated_tok = json_get_member(schemas, t+1, "deprecated");
1183+
if (is_deprecated(deprecated_tok))
1184+
continue;
1185+
11581186
if (json_tok_streq(schemas, type, "array")) {
11591187
const jsmntok_t *items;
11601188

tests/test_plugin.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,10 +3539,6 @@ def test_sql(node_factory, bitcoind):
35393539
'type': 'string'},
35403540
{'name': 'closer',
35413541
'type': 'string'},
3542-
{'name': 'funding_local_msat',
3543-
'type': 'msat'},
3544-
{'name': 'funding_remote_msat',
3545-
'type': 'msat'},
35463542
{'name': 'funding_pushed_msat',
35473543
'type': 'msat'},
35483544
{'name': 'funding_local_funds_msat',
@@ -3787,3 +3783,26 @@ def test_sql(node_factory, bitcoind):
37873783
wait_for(lambda: len(l3.rpc.listchannels()['channels']) == 2)
37883784
assert len(l3.rpc.sql("SELECT * FROM channels;")['rows']) == 2
37893785
l3.daemon.wait_for_log("Deleting channel: {}".format(scid))
3786+
3787+
# No deprecated fields!
3788+
with pytest.raises(RpcError, match='query failed with no such column: funding_local_msat'):
3789+
l2.rpc.sql("SELECT funding_local_msat FROM peerchannels;")
3790+
3791+
with pytest.raises(RpcError, match='query failed with no such column: funding_remote_msat'):
3792+
l2.rpc.sql("SELECT funding_remote_msat FROM peerchannels;")
3793+
3794+
with pytest.raises(RpcError, match='query failed with no such table: peers_channels'):
3795+
l2.rpc.sql("SELECT * FROM peers_channels;")
3796+
3797+
3798+
def test_sql_deprecated(node_factory, bitcoind):
3799+
# deprecated-apis breaks schemas...
3800+
l1 = node_factory.get_node(start=False, options={'allow-deprecated-apis': True})
3801+
l1.rpc.check_request_schemas = False
3802+
l1.start()
3803+
3804+
# FIXME: we have no fields which have been deprecated since sql plugin was
3805+
# introduced. When we do, add them here! (I manually tested a fake one)
3806+
3807+
# ret = l1.rpc.sql("SELECT funding_local_msat, funding_remote_msat FROM peerchannels;")
3808+
# assert ret == {'rows': []}

0 commit comments

Comments
 (0)