item/migrations/0006_add_annotation_sequence.py broken #2857

Closed
opened 2015-11-10 23:39:51 +00:00 by wjt · 3 comments

revision 5048 https://wiki.0x2620.org/changeset/pandora%2C5048 moved the code to fill in null public_ids in annotations over from annotation/migrations, but now init_db in a clean install fails:

Initialize database...
initializing database...
Traceback (most recent call last):
  File "/srv/pandora/pandora/manage.py", line 25, in <module>
    execute_manager(settings)
  ...
  File "/srv/pandora/pandora/item/migrations/0006_add_annotation_sequence.py", line 24, in forwards
    Annotation = orm['annotation.Annotation']
  File "/srv/pandora/local/lib/python2.7/site-packages/south/orm.py", line 172, in __getitem__
    raise KeyError("The model '%s' from the app '%s' is not available in this migration." % (model, app))
KeyError: "The model 'annotation' from the app 'annotation' is not available in this migration."

UPDATE 1

The "obvious" change to define 'annotation.annotation' and 'clip.clip' in the 'models' dictionary in the migration doesn't do the trick – I guess the entire 'item' app is set up before the 'annotation' app:

initializing database...
Traceback (most recent call last):
  File "/srv/pandora/pandora/manage.py", line 25, in <module>
    execute_manager(settings)
  ...
  File "/srv/pandora/pandora/item/migrations/0006_add_annotation_sequence.py", line 26, in forwards
    for annotation in Annotation.objects.filter(public_id=None).order_by('item'):
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
    self._fill_cache()
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
    self._result_cache.append(self._iter.next())
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/srv/pandora/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: relation "annotation_annotation" does not exist
LINE 1: ..."."item_id", "annotation_annotation"."start" FROM "annotatio...
revision 5048 <https://wiki.0x2620.org/changeset/pandora%2C5048> moved the code to fill in null public_ids in annotations over from annotation/migrations, but now init_db in a clean install fails: ``` Initialize database... initializing database... Traceback (most recent call last): File "/srv/pandora/pandora/manage.py", line 25, in <module> execute_manager(settings) ... File "/srv/pandora/pandora/item/migrations/0006_add_annotation_sequence.py", line 24, in forwards Annotation = orm['annotation.Annotation'] File "/srv/pandora/local/lib/python2.7/site-packages/south/orm.py", line 172, in __getitem__ raise KeyError("The model '%s' from the app '%s' is not available in this migration." % (model, app)) KeyError: "The model 'annotation' from the app 'annotation' is not available in this migration." UPDATE 1 ``` The "obvious" change to define 'annotation.annotation' and 'clip.clip' in the 'models' dictionary in the migration doesn't do the trick – I guess the entire 'item' app is set up before the 'annotation' app: ``` initializing database... Traceback (most recent call last): File "/srv/pandora/pandora/manage.py", line 25, in <module> execute_manager(settings) ... File "/srv/pandora/pandora/item/migrations/0006_add_annotation_sequence.py", line 26, in forwards for annotation in Annotation.objects.filter(public_id=None).order_by('item'): File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 118, in _result_iter self._fill_cache() File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache self._result_cache.append(self._iter.next()) File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator for row in compiler.results_iter(): File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter for rows in self.execute_sql(MULTI): File "/srv/pandora/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql cursor.execute(sql, params) File "/srv/pandora/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute return self.cursor.execute(query, args) django.db.utils.DatabaseError: relation "annotation_annotation" does not exist LINE 1: ..."."item_id", "annotation_annotation"."start" FROM "annotatio... ```
j added the
backend
label 2015-11-10 23:39:51 +00:00
j added this to the 14.04 milestone 2015-11-10 23:39:51 +00:00
j self-assigned this 2015-11-10 23:39:51 +00:00
j added the
normal
defect
labels 2015-11-10 23:39:51 +00:00
Owner

Only calling that part if there are items in the database looks like an ok fix for this: []changeset:pandora,5069

Only calling that part if there are items in the database looks like an ok fix for this: []changeset:pandora,5069
j added the
fixed
label 2015-11-11 09:06:27 +00:00
j closed this issue 2015-11-11 09:06:27 +00:00
Author

It does the trick for new installs, thanks!

I'm not sure that this migration would actually run successfully if there is data, because it still refers to orm['annotation.Annotation'] but that table is not one of those frozen in the models dictionary. (I could be wrong?)

It does the trick for new installs, thanks! I'm not sure that this migration would actually run successfully if there is data, because it still refers to `orm['annotation.Annotation']` but that table is not one of those frozen in the `models` dictionary. (I could be wrong?)
Owner

You are right, orm[..] can only be used for frozen models. The code already imports item.models directly and with it the Annotation model.
It was also looping over all annotations twice. Fixed in []changeset:pandora,5070

You are right, `orm[..]` can only be used for frozen models. The code already imports item.models directly and with it the Annotation model. It was also looping over all annotations twice. Fixed in []changeset:pandora,5070
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: 0x2620/pandora#2857
No description provided.