tenants2 icon indicating copy to clipboard operation
tenants2 copied to clipboard

DDO SQL query sometimes fails with "function does not exist"

Open toolness opened this issue 5 years ago • 1 comments

This has happened twice now; once in reference to a WoW-specific function, I think, and just now for a function provided by NYCDB:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/graphql/execution/executor.py", line 450, in resolve_or_error
    return executor.execute(resolve_fn, source, info, **args)
  File "/usr/local/lib/python3.7/site-packages/graphql/execution/executors/sync.py", line 16, in execute
    return fn(*args, **kwargs)
  File "/tenants2/data_driven_onboarding/schema.py", line 209, in resolve_ddo_suggestions
    row = cached_run_ddo_sql_query(props.pad_bbl)
  File "/tenants2/data_driven_onboarding/schema.py", line 222, in cached_run_ddo_sql_query
    return cache.get_or_set(cache_key, lambda: run_ddo_sql_query(bbl))
  File "/usr/local/lib/python3.7/site-packages/django/core/cache/backends/base.py", line 167, in get_or_set
    default = default()
  File "/tenants2/data_driven_onboarding/schema.py", line 222, in <lambda>
    return cache.get_or_set(cache_key, lambda: run_ddo_sql_query(bbl))
  File "/tenants2/data_driven_onboarding/schema.py", line 228, in run_ddo_sql_query
    cursor.execute(sql_query, {'bbl': bbl})
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
graphql.error.located_error.GraphQLLocatedError: function anyarray_uniq(integer[]) does not exist
LINE 3:     anyarray_uniq(array_cat_agg(q.uniqregids)) as uniqregids
            ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
QUERY:  
  SELECT
    anyarray_uniq(array_cat_agg(q.uniqregids)) as uniqregids
  FROM (
    SELECT rbas.uniqregids
    FROM hpd_business_addresses AS rbas
    WHERE _regid = any(rbas.uniqregids)
  ) AS q;

CONTEXT:  SQL function "get_regids_from_regid_by_bisaddr" during startup
SQL function "get_assoc_addrs_from_bbl" statement 1

The errors aren't easily reproducible. They also happen at a time when I think the relevant data is being updated by our auto-updating infrastructure, so I think something is amiss with our auto-updating infrastructure here, because it should be updating the DB without any adverse effects on already-running queries. I'll cross-post an issue to our auto-updating code.

toolness avatar Sep 03 '19 13:09 toolness

This issue might also be handled by changing something in NYCDB.

anyarray_uniq is defined here src/nycdb/sql/hpd_registrations/anyarray_uniq.sql. There's a handful of utility sql functions defined in sql/hpd_registrations, but that's probably not the best place for them. We should consider moving all those common utility functions somewhere else, perhaps in some nycdb database setup step.

aepyornis avatar Sep 11 '19 15:09 aepyornis