'NoneType' object has no attribute 'uri'

Bug #1732547 reported by james beedy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PostgreSQL Charm
Invalid
Critical
Unassigned
pgsql Interface for charms.reactive
Fix Released
Critical
Stuart Bishop

Bug Description

still hitting this every 1/5

unit-pdl-api-3: 14:04:50 INFO unit.pdl-api/3.juju-log pgsql:68: Invoking reactive handler: reactive/pdl_api.py:98:get_set_postgresql_data
unit-pdl-api-3: 14:04:51 ERROR unit.pdl-api/3.juju-log pgsql:68: Hook error:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/__init__.py", line 97, in main
    bus.dispatch(restricted=restricted_mode)
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 375, in dispatch
    _invoke(other_handlers)
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 351, in _invoke
    handler.invoke()
  File "/usr/local/lib/python3.5/dist-packages/charms/reactive/bus.py", line 173, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-pdl-api-3/charm/reactive/pdl_api.py", line 106, in get_set_postgresql_data
    kv.set('db_uri', pgsql.master.uri)
AttributeError: 'NoneType' object has no attribute 'uri'

Stuart Bishop (stub)
description: updated
Revision history for this message
Stuart Bishop (stub) wrote :

If pgsql.master is None, it means the master is not yet available. Handlers should generally wait for the relname.master.available state, at which point they can expect pgsql.master to be valid and pgsql.master.uri to work.

Is the handler guarded by @when('XXXX.master.available'), or some other state like XXX.connected ?

Changed in postgresql-charm:
status: New → Incomplete
Revision history for this message
james beedy (jamesbeedy) wrote :
Stuart Bishop (stub)
Changed in postgresql-charm:
status: Incomplete → Triaged
importance: Undecided → Critical
Changed in interface-pgsql:
status: New → Triaged
importance: Undecided → Critical
Revision history for this message
Stuart Bishop (stub) wrote :

This will occur if the .master.available state is already set and the client calls any of the set_* methods. The state will remain set, but the .master property will start returning None because the master database is no longer available, because the requested database properties do not yet match what is being offered by the PostgreSQL master unit.

1) PostgreSQL unit runs its relation-joined and relation-changed hooks, advertising connection details to the client
2) Client runs its relation-joined hook, setting the .master.available state because the master database is available
3) In this or a later hook, client calls set_database. For the remainder of the hook, and all further hooks until the PostgreSQL server has run its relation-changed hook, the .master.available state remains set while the .master property returns None.

Fix is to reset the states in the set_* methods.

Revision history for this message
Stuart Bishop (stub) wrote :

The state is already being reset in the set_* methods. The _set_value helper method removes the {relname}.master.available state at the same time it publishes the requested changes on the relation.

I'm at a loss how the example code could end up in such a situation.

Revision history for this message
james beedy (jamesbeedy) wrote :

@stub I haven't hit this in quite some time now .... given I haven't been spinning up psql instances as frequently as before. Its fine by me if you want to close this out.

Revision history for this message
Stuart Bishop (stub) wrote :

This stuff pretty much got rewritten with an update to use the new Endpoint base from charms.reactive. So calling this fixed released and looking forward to brand new bugs ;)

Changed in interface-pgsql:
status: Triaged → Fix Released
Changed in postgresql-charm:
status: Triaged → Invalid
Changed in interface-pgsql:
assignee: nobody → Stuart Bishop (stub)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.