Merge lp:~raoul-snyman/openlp/bug-714510 into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: 1596
Proposed branch: lp:~raoul-snyman/openlp/bug-714510
Merge into: lp:openlp
Diff against target: 83 lines (+5/-25)
3 files modified
openlp/plugins/songs/lib/db.py (+3/-24)
openlp/plugins/songs/lib/mediaitem.py (+1/-0)
openlp/plugins/songs/lib/xml.py (+1/-1)
To merge this branch: bzr merge lp:~raoul-snyman/openlp/bug-714510
Reviewer Review Type Date Requested Status
Jonathan Corwin (community) Approve
Review via email: mp+62866@code.launchpad.net

This proposal supersedes a proposal from 2011-05-30.

Commit message

Fix bug #714510 by removing the unnecessary indexes and defaulting the song_book_id on the songs table to NULL instead of 0.

Description of the change

Fix bug #714510 by removing the indexes, which were unnecessary and caused various foreign key constraints in real relational databases like InnoDB and PostgreSQL. I also defaulted the song book id on songs to NULL instead of 0, since NULL is a valid value for foreign keys.

To post a comment you must log in.
Revision history for this message
Jonathan Corwin (j-corwin) wrote : Posted in a previous version of this proposal
Download full text (4.2 KiB)

Part way there, I was able to start OpenLP and create a new song.
Then I loaded an existing service file which contained songs that weren't in the database, and I got:

Traceback (most recent call last):
  File "C:\Users\jonathan\Documents\projects\openlp\bug-714510\openlp\plugins\songs\lib\mediaitem.py", line 480, in serviceLoad
    editId = self.openLyrics.xml_to_song(item.xml_version)
  File "C:\Users\jonathan\Documents\projects\openlp\bug-714510\openlp\plugins\songs\lib\xml.py", line 343, in xml_to_song
    self.manager.save_object(song)
  File "C:\Users\jonathan\Documents\projects\openlp\bug-714510\openlp\core\lib\db.py", line 152, in save_object
    self.session.commit()
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\scoping.py", line 139, in do
    return getattr(self.registry(), name)(*args, **kwargs)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\session.py", line 614, in commit
    self.transaction.commit()
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\session.py", line 385, in commit
    self._prepare_impl()
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\session.py", line 369, in _prepare_impl
    self.session.flush()
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\session.py", line 1388, in flush
    self._flush(objects)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\session.py", line 1469, in _flush
    flush_context.execute()
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\unitofwork.py", line 302, in execute
    rec.execute(self)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\unitofwork.py", line 446, in execute
    uow
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\orm\mapper.py", line 1878, in _save_obj
    execute(statement, params)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\base.py", line 1191, in execute
    params)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\base.py", line 1271, in _execute_clauseelement
    return self.__execute_context(context)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\base.py", line 1302, in __execute_context
    context.parameters[0], context=context)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\base.py", line 1401, in _cursor_execute
    context)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\base.py", line 1394, in _cursor_execute
    context)
  File "C:\Python27\lib\site-packages\sqlalchemy-0.6.6-py2.7.egg\sqlalchemy\engine\default.py", line 299, in do_execute
    cursor.execute(statement, parameters)
  File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 174, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
IntegrityError: (IntegrityError) (1452, 'Cannot add or update a child row: a ...

Read more...

Revision history for this message
Andreas Preikschat (googol-deactivatedaccount) wrote :

Sure we need the import re?

;-)

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Yes, when I tried to import some songs, it failed because the import was not there.

Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

See line 452, or 453 with the "import re" line.

Revision history for this message
Jonathan Corwin (j-corwin) :
review: Approve
Revision history for this message
Tim Bentley (trb143) : Posted in a previous version of this proposal
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/songs/lib/db.py'
--- openlp/plugins/songs/lib/db.py 2011-05-27 08:21:23 +0000
+++ openlp/plugins/songs/lib/db.py 2011-05-30 11:23:23 +0000
@@ -165,7 +165,7 @@
165 Column(u'id', types.Integer, primary_key=True),165 Column(u'id', types.Integer, primary_key=True),
166 Column(u'first_name', types.Unicode(128)),166 Column(u'first_name', types.Unicode(128)),
167 Column(u'last_name', types.Unicode(128)),167 Column(u'last_name', types.Unicode(128)),
168 Column(u'display_name', types.Unicode(255), nullable=False)168 Column(u'display_name', types.Unicode(255), index=True, nullable=False)
169 )169 )
170170
171 # Definition of the "media_files" table171 # Definition of the "media_files" table
@@ -186,7 +186,7 @@
186 songs_table = Table(u'songs', metadata,186 songs_table = Table(u'songs', metadata,
187 Column(u'id', types.Integer, primary_key=True),187 Column(u'id', types.Integer, primary_key=True),
188 Column(u'song_book_id', types.Integer,188 Column(u'song_book_id', types.Integer,
189 ForeignKey(u'song_books.id'), default=0),189 ForeignKey(u'song_books.id'), default=None),
190 Column(u'title', types.Unicode(255), nullable=False),190 Column(u'title', types.Unicode(255), nullable=False),
191 Column(u'alternate_title', types.Unicode(255)),191 Column(u'alternate_title', types.Unicode(255)),
192 Column(u'lyrics', types.UnicodeText, nullable=False),192 Column(u'lyrics', types.UnicodeText, nullable=False),
@@ -203,7 +203,7 @@
203 # Definition of the "topics" table203 # Definition of the "topics" table
204 topics_table = Table(u'topics', metadata,204 topics_table = Table(u'topics', metadata,
205 Column(u'id', types.Integer, primary_key=True),205 Column(u'id', types.Integer, primary_key=True),
206 Column(u'name', types.Unicode(128), nullable=False)206 Column(u'name', types.Unicode(128), index=True, nullable=False)
207 )207 )
208208
209 # Definition of the "authors_songs" table209 # Definition of the "authors_songs" table
@@ -230,27 +230,6 @@
230 ForeignKey(u'topics.id'), primary_key=True)230 ForeignKey(u'topics.id'), primary_key=True)
231 )231 )
232232
233 # Define table indexes
234 Index(u'authors_id', authors_table.c.id)
235 Index(u'authors_display_name_id', authors_table.c.display_name,
236 authors_table.c.id)
237 Index(u'media_files_id', media_files_table.c.id)
238 Index(u'song_books_id', song_books_table.c.id)
239 Index(u'songs_id', songs_table.c.id)
240 Index(u'topics_id', topics_table.c.id)
241 Index(u'authors_songs_author', authors_songs_table.c.author_id,
242 authors_songs_table.c.song_id)
243 Index(u'authors_songs_song', authors_songs_table.c.song_id,
244 authors_songs_table.c.author_id)
245 Index(u'media_files_songs_file', media_files_songs_table.c.media_file_id,
246 media_files_songs_table.c.song_id)
247 Index(u'media_files_songs_song', media_files_songs_table.c.song_id,
248 media_files_songs_table.c.media_file_id)
249 Index(u'topics_song_topic', songs_topics_table.c.topic_id,
250 songs_topics_table.c.song_id)
251 Index(u'topics_song_song', songs_topics_table.c.song_id,
252 songs_topics_table.c.topic_id)
253
254 mapper(Author, authors_table)233 mapper(Author, authors_table)
255 mapper(Book, song_books_table)234 mapper(Book, song_books_table)
256 mapper(MediaFile, media_files_table)235 mapper(MediaFile, media_files_table)
257236
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py 2011-05-28 19:38:19 +0000
+++ openlp/plugins/songs/lib/mediaitem.py 2011-05-30 11:23:23 +0000
@@ -27,6 +27,7 @@
2727
28import logging28import logging
29import locale29import locale
30import re
3031
31from PyQt4 import QtCore, QtGui32from PyQt4 import QtCore, QtGui
32from sqlalchemy.sql import or_33from sqlalchemy.sql import or_
3334
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2011-05-26 17:11:22 +0000
+++ openlp/plugins/songs/lib/xml.py 2011-05-30 11:23:23 +0000
@@ -514,7 +514,7 @@
514 ``song``514 ``song``
515 The song object.515 The song object.
516 """516 """
517 song.song_book_id = 0517 song.song_book_id = None
518 song.song_number = u''518 song.song_number = u''
519 if hasattr(properties, u'songbooks'):519 if hasattr(properties, u'songbooks'):
520 for songbook in properties.songbooks.songbook:520 for songbook in properties.songbooks.songbook: