add: config to emit warning for legacy target names
Adds the `url_use_legacy_target_names` config. Enabled (default): * It allows using the resource name in filters, orders or limits when it has an alias, e.g. `table?select=alias:target(*)&target.id=eq.1` * Logs a WARNING with a hint to use the alias * Returns a Warning header in the response Disabled: * It returns an error, only the alias is allowed * No warnings returned This feature is deprecated
This commit is contained in:
committed by
Laurence Isla
parent
2fa8de4e52
commit
490d1dc5d3
@@ -2089,3 +2089,33 @@ def test_work_mem_in_role_settings(defaultenv):
|
||||
response = postgrest.session.post("/rpc/get_work_mem", headers=headers)
|
||||
assert response.status_code == 200
|
||||
assert response.text == '"3MB"'
|
||||
|
||||
|
||||
@pytest.mark.parametrize("enabled", ["true", "false"])
|
||||
def test_use_legacy_target_names(enabled, defaultenv):
|
||||
"Show a warning when a target name is used instead of an alias, only when config is enabled"
|
||||
|
||||
env = {
|
||||
**defaultenv,
|
||||
"PGRST_URL_USE_LEGACY_TARGET_NAMES": enabled,
|
||||
}
|
||||
|
||||
with run(env=env) as postgrest:
|
||||
response = postgrest.session.get(
|
||||
"/directors?select=name,all_films:films(title),awards_2026:awards(name)&films.order=title&awards.year=eq.2026"
|
||||
)
|
||||
|
||||
output = postgrest.read_stdout(nlines=10)
|
||||
|
||||
log_err_warning = "WARNING: Embedded resource was referenced by relation name even though it has an alias. This is deprecated and will stop working in a future release."
|
||||
log_err_hint = "Update filters, orders or limits that use `films` to `all_films`, `awards` to `awards_2026` in `GET /directors?select=name,all_films:films(title),awards_2026:awards(name)&films.order=title&awards.year=eq.2026`"
|
||||
|
||||
has_warning_log = any(log_err_warning in line for line in output)
|
||||
has_hint_log = any(log_err_hint in line for line in output)
|
||||
|
||||
if enabled == "true":
|
||||
assert response.status_code == 200
|
||||
assert has_warning_log and has_hint_log
|
||||
else:
|
||||
assert response.status_code == 400
|
||||
assert not has_warning_log and not has_hint_log
|
||||
|
||||
Reference in New Issue
Block a user