FinalsClub / karmaworld

KarmaNotes.org v3.0
GNU Affero General Public License v3.0
7 stars 6 forks source link

upload to beta shows error, but generally works. #393

Closed btbonval closed 9 years ago

btbonval commented 9 years ago

Uploaded a note. It worked and generated the correct preview. However, celery threw an error in the process.

Here's what Celery says:

[2015-01-24 03:19:16,992: INFO/MainProcess] Got task from broker: karmaworld.apps.document_upload.tasks.process_raw_document[e79409e2-bcc3-4c8e-a976-486f6c77fd50]
[2015-01-24 03:19:17,117: WARNING/PoolWorker-2] this is the mimetype of the document to check:
[2015-01-24 03:19:17,117: WARNING/PoolWorker-2] text/plain
[2015-01-24 03:19:17,118: INFO/MainProcess] URL being requested: https://www.googleapis.com/discovery/v1/apis/drive/v2/rest
[2015-01-24 03:19:17,118: INFO/MainProcess] Attempting refresh to obtain initial access_token
[2015-01-24 03:19:17,121: INFO/MainProcess] Refreshing access_token
[2015-01-24 03:19:17,362: INFO/MainProcess] URL being requested: https://www.googleapis.com/upload/drive/v2/files?convert=true&ocr=false&uploadType=resumable&alt=json
[2015-01-24 03:19:17,362: WARNING/MainProcess] new_request() takes at most 1 positional argument (2 given)
[2015-01-24 03:19:17,490: WARNING/MainProcess] new_request() takes at most 1 positional argument (2 given)
[2015-01-24 03:19:18,962: WARNING/PoolWorker-2] text -- https://docs.google.com/feeds/download/documents/export/Export?id=1ko40BkWEyo_AgdsTHQc3qNhclIMva4vgGPVVpxtsFss&exportFormat=txt
[2015-01-24 03:19:19,389: WARNING/PoolWorker-2] downloaded!
[2015-01-24 03:19:19,390: WARNING/PoolWorker-2] html -- https://docs.google.com/feeds/download/documents/export/Export?id=1ko40BkWEyo_AgdsTHQc3qNhclIMva4vgGPVVpxtsFss&exportFormat=html
[2015-01-24 03:19:19,572: WARNING/PoolWorker-2] downloaded!
[2015-01-24 03:19:19,687: INFO/MainProcess] Note Note at https://www.filepicker.io/api/file/SPtD6tVaQwqPvsu4ZeAO (from None) (1126) has no text, will not add to IndexDen
[2015-01-24 03:19:19,855: ERROR/MainProcess] karmaworld.apps.document_upload.tasks.process_raw_document[e79409e2-bcc3-4c8e-a976-486f6c77fd50]: Traceback (most recent call last):
  File "/app/karmaworld/apps/document_upload/tasks.py", line 16, in process_raw_document
    convert_raw_document(raw_document, user=user)
  File "/app/karmaworld/apps/notes/gdrive.py", line 244, in convert_raw_document
    note.user = user
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/fields/related.py", line 405, in __set__
    self.field.name, self.field.rel.to._meta.object_name))
ValueError: Cannot assign "<django.contrib.auth.models.AnonymousUser object at 0x4716a50>": "Note.user" must be a "User" instance.

[2015-01-24 03:19:20,000: INFO/MainProcess] Task karmaworld.apps.document_upload.tasks.process_raw_document[e79409e2-bcc3-4c8e-a976-486f6c77fd50] succeeded in 2.98645997047s: None
btbonval commented 9 years ago

Looks like the proper solution to remove the above error is to check for not just if user but also and type(user) is not AnonymousUser: https://github.com/FinalsClub/karmaworld/blob/master/karmaworld/apps/notes/gdrive.py#L243

note.text is set, but crashes prior to the save. https://github.com/FinalsClub/karmaworld/blob/master/karmaworld/apps/notes/gdrive.py#L229 https://github.com/FinalsClub/karmaworld/blob/master/karmaworld/apps/notes/gdrive.py#L256

btbonval commented 9 years ago

Oh sweet, User and AnonymousUser both support is_anonymous() method. Just checked in console and it appears to work as expected. if user and not user.is_anonymous() seems like the right solution.

btbonval commented 9 years ago

Yup, that fixed the preview. Strange that there is still a mention of no text found for IndexDen, followed by a mention that the file will be indexed.

[2015-01-27 14:16:09,636: WARNING/PoolWorker-4] html -- https://docs.google.com/feeds/download/documents/export/Export?id=1xNCJu4mADm1OAYPd147xCdmF9UFTMIXBwXzZKi3WGOA&exportFormat=html
[2015-01-27 14:16:09,859: WARNING/PoolWorker-4] downloaded!
[2015-01-27 14:16:12,497: INFO/MainProcess] Note Note at https://www.filepicker.io/api/file/plgR1vAR4qa6gF4HIfLU (from None) (1128) has no text, will not add to IndexDen
[2015-01-27 14:16:13,714: INFO/MainProcess] Indexing Note at https://www.filepicker.io/api/file/plgR1vAR4qa6gF4HIfLU (from None) (1128)

The no text notice appears twice in the code:

The indexing notice appears twice in the code:

The first two instances of each notice appear in add_note while the second two instances of each case appear in update_note. It looks like no text is found for add_note but is found for update_note.

That's annoying, but not worth spending time to fix. It looks like the preview text is generated and indexed. Pushing fix to master and closing ticket.