Repository: praw-dev/praw

Issue:
`LiveUpdate` objects have no `contrib` attribute
## Issue Description

`LiveUpdate` objects have no [`contrib` attribute](https://github.com/praw-dev/praw/blob/32e1f2eb57d3c7fa15c59537406f49b18998eb45/praw/models/reddit/live.py#L527) when those objects are initialized with responses from reddit:

```
$ cat lm.py
import praw
from praw.models import LiveUpdate

thread_id = 'z20sk2xfmvry'
update_id = '11e8e596-4ab5-11e7-97c4-0ed64337f69e'

reddit = praw.Reddit("nmtake")
update = reddit.live(thread_id).updates().next()
print(update.created)
print(update.contrib)
```

```
$ python lm.py
1496781520.0
Traceback (most recent call last):
  File "lm.py", line 10, in <module>
    print(update.contrib)
  File "/usr/local/lib/python2.7/site-packages/praw/models/reddit/base.py", line 34, in __getattr__
    .format(self.__class__.__name__, attribute))
AttributeError: 'LiveUpdate' object has no attribute 'contrib'
```

This bug is due to [this improper initialization of LiveUpdate instance](https://github.com/praw-dev/praw/blob/32e1f2eb57d3c7fa15c59537406f49b18998eb45/praw/models/reddit/live.py#L573). (`_contrib` attribute isn't set in the first clause). I'll submit a fix today.

## System Information

```
    PRAW Version: 4.5.1
  Python Version: 2.5.1
Operating System: OS X 10.11.6
```


Discussion:

Resolving patch:
diff --git a/praw/models/reddit/live.py b/praw/models/reddit/live.py
--- a/praw/models/reddit/live.py
+++ b/praw/models/reddit/live.py
@@ -571,17 +571,19 @@ def __init__(self, reddit, thread_id=None, update_id=None, _data=None):
            update.author     # raise ``AttributeError``
         """
         if _data is not None:
+            # Since _data (part of JSON returned from reddit) have no
+            # thread ID, self._thread must be set by the caller of
+            # LiveUpdate(). See the code of LiveThread.updates() for example.
             super(LiveUpdate, self).__init__(reddit, _data)
-            self._fetched = True
         elif thread_id and update_id:
             super(LiveUpdate, self).__init__(reddit, None)
             self._thread = LiveThread(self._reddit, thread_id)
             self.id = update_id  # pylint: disable=invalid-name
-            self._fetched = True
-            self._contrib = None
         else:
             raise TypeError('Either `thread_id` and `update_id`, or '
                             '`_data` must be provided.')
+        self._fetched = True
+        self._contrib = None
 
     def __setattr__(self, attribute, value):
         """Objectify author."""


Test patch:
diff --git a/tests/unit/models/reddit/test_live.py b/tests/unit/models/reddit/test_live.py
--- a/tests/unit/models/reddit/test_live.py
+++ b/tests/unit/models/reddit/test_live.py
@@ -148,6 +148,10 @@ def test_contrib(self):
         update = LiveUpdate(self.reddit, thread_id, update_id)
         assert isinstance(update.contrib, LiveUpdateContribution)
 
+        data = {'id': 'dummy_update_id', 'author': 'dummy_author'}
+        update = LiveUpdate(self.reddit, _data=data)
+        assert isinstance(update.contrib, LiveUpdateContribution)
+
     def test_setattr(self):
         data = {'id': 'dummy_update_id', 'author': 'dummy_author'}
         update = LiveUpdate(self.reddit, _data=data)