Repository: librephotos/librephotos
Issue: exception in backend NetworkXError

## 🐛 Bug Report

* [ ] I am including my log files in zip format.
* [x] I have looked for similar issues among all the former issues including closed ones.

### What Operating system and version is LibrePhotos running on:
Debian Unstable

### What architecture is LibrePhotos running on:
x64


### How is LibrePhotos installed:
Docker


### If running via Docker or Kubernetes please list version including docker-compose:
3.8

### Are you running LibrePhotos on a virtual machine if so please list:
No

### How is you picture library mounted on the host (or in the virtual machine):
Local file system BTRFS


### Description of issue:

Exception seen when doing some random operation on the UI

```
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:13 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:15 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:17 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:19 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:21 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:23 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:25 +0000] "GET /api/rqavailable/ HTTP/1.1" 200 427 "http://lenovo:3000/recent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
backend_1   | Internal Server Error: /api/socialgraph
backend_1   | Traceback (most recent call last):
backend_1   |   File "/usr/local/lib/python3.8/site-packages/networkx/utils/decorators.py", line 396, in _random_state
backend_1   |     random_state_arg = args[random_state_index]
backend_1   | IndexError: tuple index out of range
backend_1   | 
backend_1   | The above exception was the direct cause of the following exception:
backend_1   | 
backend_1   | Traceback (most recent call last):
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
backend_1   |     response = get_response(request)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
backend_1   |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
backend_1   |     return view_func(*args, **kwargs)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
backend_1   |     return self.dispatch(request, *args, **kwargs)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
backend_1   |     response = self.handle_exception(exc)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
backend_1   |     self.raise_uncaught_exception(exc)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
backend_1   |     raise exc
backend_1   |   File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
backend_1   |     response = handler(request, *args, **kwargs)
backend_1   |   File "/code/api/views.py", line 1444, in get
backend_1   |     res = build_social_graph(request.user)
backend_1   |   File "/code/api/social_graph.py", line 25, in build_social_graph
backend_1   |     pos = nx.spring_layout(G, k=1/2, scale=1000, iterations=20)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/decorator.py", line 231, in fun
backend_1   |     return caller(func, *(extras + args), **kw)
backend_1   |   File "/usr/local/lib/python3.8/site-packages/networkx/utils/decorators.py", line 400, in _random_state
backend_1   |     raise nx.NetworkXError("random_state_index is incorrect") from e
backend_1   | networkx.exception.NetworkXError: random_state_index is incorrect
proxy_1     | 10.42.0.24 - - [22/Apr/2021:13:32:25 +0000] "GET /api/socialgraph HTTP/1.1" 500 145 "http://lenovo:3000/socialgraph" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36"
```

### How can we reproduce it:

I think it triggered when clicking feature **Social Graph**


Changed files:
api/social_graph.py

diff --git a/api/social_graph.py b/api/social_graph.py
index 758efd4..c75d006 100644
--- a/api/social_graph.py
+++ b/api/social_graph.py
@@ -20,8 +20,12 @@ def build_social_graph(user):
     G = nx.Graph()
     with connection.cursor() as cursor:
         cursor.execute(query)
-        for link in cursor.fetchall():
+        links = cursor.fetchall()
+        if len(links) == 0:
+            return {"nodes" : [], "links" : [] }
+        for link in links:
             G.add_edge(link[0],link[1])
+            nodata = False
     pos = nx.spring_layout(G, k=1/2, scale=1000, iterations=20)
     return { "nodes" : [{'id':node,'x':pos[0],'y':pos[1]} for node,pos in pos.items()],
              "links" : [{'source':pair[0], 'target':pair[1]} for pair in G.edges()] }