{"message": "Internal Server Error"} when I try import buckets

When I try to import buckets, I get the error {"message": "Internal Server Error"}. I exported with AW v0.8.4 installed on Windows, and trying to import to AW v.0.9.2 on Windows. Perhaps a problem could arise due to the same PC name, but I changed the values buckets, id, hostname to others. What to do?

I specifically exported the data in order to export it after reinstalling Windows, but at the moment I just can’t do it.

My first try would be to

  1. Shut down all watchers (to make sure they are not re-created right after)
  2. Delete all buckets in the web-ui
  3. Try to import again

This way you will be sure that there are no conflicting bucket names.

If this is not an option or does not work I would take a look at the aw-server logs to see what the “Internal Server Error” actually is.

Followed three steps, as you described, first, then I tried to import a bucket with probably the same computer name as now (aw-watcher-window_Rakleed-PC) and received a null error. Then I decided to import a bucket with a completely different computer name (aw-watcher-window_Rakleed-P), and again received an error {"message": "Internal Server Error"}. Log below. What to do?

2020-03-24 17:49:16 [INFO ]: Using storage method: peewee  (aw_server.main:26)
2020-03-24 17:49:16 [INFO ]: Starting up...  (aw_server.main:31)
2020-03-24 17:49:17 [INFO ]: Using database file: C:\Users\Rakleed-PC\AppData\Local\activitywatch\activitywatch\aw-server\peewee-sqlite.v2.db  (aw_datastore.storages.peewee:90)
2020-03-24 17:49:17 [INFO ]:  * Running on http://localhost:5600/ (Press CTRL+C to quit)  (werkzeug:122)
2020-03-24 17:49:20 [INFO ]: 404 (127.0.0.1): GET /img/icons/android-chrome-192x192.png HTTP/1.1  (flask:25)
2020-03-24 17:50:03 [INFO ]: 404 (127.0.0.1): GET /img/icons/android-chrome-192x192.png HTTP/1.1  (flask:25)
2020-03-24 17:50:33 [INFO ]: Deleting bucket 'aw-watcher-web-chrome'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:50:36 [INFO ]: Deleting bucket 'aw-watcher-window_Rakleed-PC'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:50:40 [INFO ]: Deleting bucket 'aw-watcher-afk_Rakleed-PC'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:50:42 [INFO ]: Deleting bucket 'aw-watcher-web-firefox'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:50:46 [INFO ]: Deleting bucket 'aw-watcher-window_Rakleed-P'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:50:49 [INFO ]: Deleting bucket 'aw-stopwatch'  (aw_datastore.datastore.Datastore:42)
2020-03-24 17:52:44 [INFO ]: Importing bucket aw-watcher-window_Rakleed-PC  (aw_server.api:102)
2020-03-24 17:52:44 [INFO ]: Creating bucket 'aw-watcher-window_Rakleed-PC'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:53:14 [INFO ]: Importing bucket aw-watcher-afk_Rakleed-PC  (aw_server.api:102)
2020-03-24 17:53:14 [INFO ]: Creating bucket 'aw-watcher-afk_Rakleed-PC'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:53:16 [INFO ]: Importing bucket aw-watcher-web-chrome  (aw_server.api:102)
2020-03-24 17:53:16 [INFO ]: Creating bucket 'aw-watcher-web-chrome'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:53:46 [INFO ]: Importing bucket aw-watcher-web-firefox  (aw_server.api:102)
2020-03-24 17:53:46 [INFO ]: Creating bucket 'aw-watcher-web-firefox'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:53:46 [INFO ]: Importing bucket aw-stopwatch  (aw_server.api:102)
2020-03-24 17:53:46 [INFO ]: Creating bucket 'aw-stopwatch'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:53:49 [INFO ]: 404 (127.0.0.1): GET /favicon.ico HTTP/1.1  (flask:25)
2020-03-24 17:54:03 [INFO ]: 404 (127.0.0.1): GET /img/icons/android-chrome-192x192.png HTTP/1.1  (flask:25)
2020-03-24 17:55:08 [INFO ]: Importing bucket aw-watcher-window_Rakleed-P  (aw_server.api:102)
2020-03-24 17:55:08 [INFO ]: Creating bucket 'aw-watcher-window_Rakleed-P'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:55:34 [INFO ]: Importing bucket aw-watcher-afk_Rakleed-PC  (aw_server.api:102)
2020-03-24 17:55:34 [INFO ]: Creating bucket 'aw-watcher-afk_Rakleed-PC'  (aw_datastore.datastore.Datastore:37)
2020-03-24 17:55:34 [ERROR]: Exception on /api/0/import [POST]  (aw-server:1891)
Traceback (most recent call last):
  File "site-packages\peewee.py", line 3057, in execute_sql
sqlite3.IntegrityError: UNIQUE constraint failed: bucketmodel.id

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "site-packages\flask\app.py", line 1949, in full_dispatch_request
  File "site-packages\flask\app.py", line 1935, in dispatch_request
  File "site-packages\flask_restx\api.py", line 339, in wrapper
  File "site-packages\flask\views.py", line 89, in view
  File "site-packages\flask_restx\resource.py", line 44, in dispatch_request
  File "aw_server\rest.py", line 292, in post
  File "aw_server\api.py", line 117, in import_all
  File "aw_server\api.py", line 111, in import_bucket
  File "aw_datastore\datastore.py", line 38, in create_bucket
  File "aw_datastore\storages\peewee.py", line 110, in create_bucket
  File "site-packages\peewee.py", line 6235, in create
  File "site-packages\peewee.py", line 6433, in save
  File "site-packages\peewee.py", line 1845, in inner
  File "site-packages\peewee.py", line 1916, in execute
  File "site-packages\peewee.py", line 2665, in _execute
  File "site-packages\peewee.py", line 2400, in _execute
  File "site-packages\peewee.py", line 3070, in execute
  File "site-packages\peewee.py", line 3064, in execute_sql
  File "site-packages\peewee.py", line 2831, in __exit__
  File "site-packages\peewee.py", line 183, in reraise
  File "site-packages\peewee.py", line 3057, in execute_sql
peewee.IntegrityError: UNIQUE constraint failed: bucketmodel.id
2020-03-24 17:55:34 [INFO ]: 500 (127.0.0.1): POST /api/0/import HTTP/1.1  (flask:25)

If I remember correctly, when you import a bucket from the web-ui it is actually supposed to show just “null” when it succeeds (I know it’s horrible UX, but very few have used the feature yet as far as I know).

Are you sure that the import was not successful? The second error pretty much just says (in a hard to read way) that a bucket with that name already exists (the bucketmodel.id has the UNIQUE constraint which it was not able to apply, so some bucket already has that id).

Yes, indeed the import was successful at that moment, due to the null message, I decided that it was unsuccessful. And can then create a GitHub issue for you to improve UX in this case?

That would be great!

We should also fix so that there are proper error messages coming from the server that can displayed in the web-ui to the user.