Skip to content

Commit 14cec6f

Browse files
committed
Move the curried constraint parameter value to the params link in introspection
Currently, we expose the applied constraint args in the `args` link of the `schema::Constraint` type. But it already has the `params` link it inherits from `CallableObject`, so it makes sense to use that link instead.
1 parent 196c5e9 commit 14cec6f

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

docs/edgeql/introspection/constraints.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Introspection of the scalar ``maxex_100`` with focus on the constraint:
6969
... expr,
7070
... annotations: { name, @value },
7171
... subject: { name },
72-
... args: { name, @value, type: { name } },
72+
... params: { name, @value, type: { name } },
7373
... return_typemod,
7474
... return_type: { name },
7575
... errmessage,
@@ -85,7 +85,7 @@ Introspection of the scalar ``maxex_100`` with focus on the constraint:
8585
expr: '(__subject__ <= max)',
8686
annotations: {},
8787
subject: Object { name: 'default::maxex_100' },
88-
args: {
88+
params: {
8989
Object {
9090
name: 'max',
9191
type: Object { name: 'anytype' },

edb/lib/schema.edgeql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ CREATE ABSTRACT TYPE schema::VolatilitySubject {
167167
CREATE TYPE schema::Constraint
168168
EXTENDING schema::CallableObject, schema::InheritingObject
169169
{
170-
CREATE MULTI LINK args -> schema::Parameter {
171-
CREATE CONSTRAINT std::exclusive;
170+
ALTER LINK params {
172171
CREATE PROPERTY value -> std::str;
173172
};
174173
CREATE PROPERTY expr -> std::str;

edb/pgsql/metaschema.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,13 +2248,14 @@ def _get_link_view(mcls, schema_cls, field, ptr, refdict, schema):
22482248
else:
22492249
ftype = type(None)
22502250

2251-
if pn.name == 'args' and mcls is s_constraints.Constraint:
2252-
# Constraint args need special handling.
2251+
if pn.name == 'params' and mcls is s_constraints.Constraint:
2252+
# Constraint params need special handling to support
2253+
# currying (@value property injection)
22532254
link_query = f'''
22542255
SELECT
22552256
q.id AS source,
22562257
q.param_id AS target,
2257-
q.value AS value
2258+
COALESCE(q.value, '') AS value
22582259
FROM
22592260
edgedb.{mcls.__name__} AS s,
22602261
@@ -2270,7 +2271,7 @@ def _get_link_view(mcls, schema_cls, field, ptr, refdict, schema):
22702271
INNER JOIN edgedb.Parameter AS param
22712272
ON param.id = p.param_id
22722273
2273-
INNER JOIN
2274+
LEFT JOIN
22742275
UNNEST(s.args)
22752276
WITH ORDINALITY AS tv(_, value, _, num)
22762277
ON (p.num = tv.num + 1)
@@ -2297,8 +2298,6 @@ def _get_link_view(mcls, schema_cls, field, ptr, refdict, schema):
22972298
param.kind = 'VARIADIC'
22982299
22992300
) AS q
2300-
WHERE
2301-
s.subject IS NOT NULL
23022301
'''
23032302

23042303
elif pn.name == 'bases' or pn.name == 'ancestors':

tests/test_constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ async def test_constraints_ddl_02(self):
703703
r'''
704704
SELECT schema::Constraint {
705705
name,
706-
args: {
706+
params: {
707707
num,
708708
name,
709709
kind,
@@ -720,7 +720,7 @@ async def test_constraints_ddl_02(self):
720720
[
721721
{
722722
"name": 'test::mymax_ext1',
723-
"args": [
723+
"params": [
724724
{
725725
"num": 1,
726726
"kind": 'POSITIONAL',

tests/test_dump01.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,10 @@ async def _ensure_schema_data_integrity(self):
508508
} ORDER BY @index,
509509
constraints: {
510510
name,
511-
args: {
511+
params: {
512512
name,
513513
@value,
514-
},
514+
} FILTER .name != '__subject__',
515515
},
516516
}
517517
FILTER
@@ -538,7 +538,7 @@ async def _ensure_schema_data_integrity(self):
538538
'constraints': [
539539
{
540540
'name': 'default::user_int_constr',
541-
'args': [{'name': 'x', '@value': '5'}],
541+
'params': [{'name': 'x', '@value': '5'}],
542542
},
543543
],
544544
},
@@ -551,7 +551,7 @@ async def _ensure_schema_data_integrity(self):
551551
'constraints': [
552552
{
553553
'name': 'std::max_len_value',
554-
'args': [{'name': 'max', '@value': '5'}],
554+
'params': [{'name': 'max', '@value': '5'}],
555555
},
556556
],
557557
},
@@ -568,10 +568,10 @@ async def _ensure_schema_data_integrity(self):
568568
name,
569569
constraints: {
570570
name,
571-
args: {
571+
params: {
572572
name,
573573
@value,
574-
},
574+
} FILTER .name != '__subject__',
575575
},
576576
}
577577
FILTER .name IN {'m0', 'm1'}
@@ -589,7 +589,7 @@ async def _ensure_schema_data_integrity(self):
589589
'constraints': [
590590
{
591591
'name': 'default::user_int_constr',
592-
'args': [{'name': 'x', '@value': '3'}],
592+
'params': [{'name': 'x', '@value': '3'}],
593593
},
594594
],
595595
},
@@ -598,7 +598,7 @@ async def _ensure_schema_data_integrity(self):
598598
'constraints': [
599599
{
600600
'name': 'std::max_len_value',
601-
'args': [{'name': 'max', '@value': '3'}],
601+
'params': [{'name': 'max', '@value': '3'}],
602602
},
603603
],
604604
}

tests/test_edgeql_introspection.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,11 @@ async def test_edgeql_introspection_constraint_04(self):
515515
subject: {
516516
name
517517
},
518-
args: {
518+
params: {
519519
num,
520520
@value
521-
} ORDER BY .num
521+
} FILTER .name != '__subject__'
522+
ORDER BY .num
522523
}
523524
FILTER
524525
.subject.name = 'body'
@@ -530,7 +531,7 @@ async def test_edgeql_introspection_constraint_04(self):
530531
'subject': {
531532
'name': 'body'
532533
},
533-
'args': [{
534+
'params': [{
534535
'num': 1,
535536
'@value': '10000'
536537
}]
@@ -550,7 +551,11 @@ async def test_edgeql_introspection_constraint_05(self):
550551
expr,
551552
annotations: { name, @value },
552553
subject: { name },
553-
args: { name, @value, type: { name } },
554+
params: {
555+
name,
556+
@value,
557+
type: { name }
558+
} FILTER .name != '__subject__',
554559
return_typemod,
555560
return_type: { name },
556561
errmessage,
@@ -570,7 +575,7 @@ async def test_edgeql_introspection_constraint_05(self):
570575
'expr': '(__subject__ <= max)',
571576
'annotations': {},
572577
'subject': {'name': 'body'},
573-
'args': [
578+
'params': [
574579
{
575580
'name': 'max',
576581
'type': {'name': 'std::int64'},
@@ -593,7 +598,7 @@ async def test_edgeql_introspection_constraint_05(self):
593598
'expr': 'std::_is_exclusive(__subject__)',
594599
'annotations': {},
595600
'subject': {'name': 'id'},
596-
'args': {},
601+
'params': {},
597602
'return_typemod': 'SINGLETON',
598603
'return_type': {'name': 'std::bool'},
599604
'errmessage':
@@ -617,7 +622,11 @@ async def test_edgeql_introspection_constraint_06(self):
617622
expr,
618623
annotations: { name, @value },
619624
subject: { name },
620-
args: { name, @value, type: { name } },
625+
params: {
626+
name,
627+
@value,
628+
type: { name }
629+
} FILTER .name != '__subject__',
621630
return_typemod,
622631
return_type: { name },
623632
errmessage,
@@ -634,7 +643,7 @@ async def test_edgeql_introspection_constraint_06(self):
634643
'expr': 'contains(vals, __subject__)',
635644
'annotations': {},
636645
'subject': {'name': 'test::EmulatedEnum'},
637-
'args': [
646+
'params': [
638647
{
639648
'name': 'vals',
640649
'type': {'name': 'array'},

0 commit comments

Comments
 (0)