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
1=== modified file 'openlp/plugins/songs/lib/db.py'
2--- openlp/plugins/songs/lib/db.py 2011-05-27 08:21:23 +0000
3+++ openlp/plugins/songs/lib/db.py 2011-05-30 11:23:23 +0000
4@@ -165,7 +165,7 @@
5 Column(u'id', types.Integer, primary_key=True),
6 Column(u'first_name', types.Unicode(128)),
7 Column(u'last_name', types.Unicode(128)),
8- Column(u'display_name', types.Unicode(255), nullable=False)
9+ Column(u'display_name', types.Unicode(255), index=True, nullable=False)
10 )
11
12 # Definition of the "media_files" table
13@@ -186,7 +186,7 @@
14 songs_table = Table(u'songs', metadata,
15 Column(u'id', types.Integer, primary_key=True),
16 Column(u'song_book_id', types.Integer,
17- ForeignKey(u'song_books.id'), default=0),
18+ ForeignKey(u'song_books.id'), default=None),
19 Column(u'title', types.Unicode(255), nullable=False),
20 Column(u'alternate_title', types.Unicode(255)),
21 Column(u'lyrics', types.UnicodeText, nullable=False),
22@@ -203,7 +203,7 @@
23 # Definition of the "topics" table
24 topics_table = Table(u'topics', metadata,
25 Column(u'id', types.Integer, primary_key=True),
26- Column(u'name', types.Unicode(128), nullable=False)
27+ Column(u'name', types.Unicode(128), index=True, nullable=False)
28 )
29
30 # Definition of the "authors_songs" table
31@@ -230,27 +230,6 @@
32 ForeignKey(u'topics.id'), primary_key=True)
33 )
34
35- # Define table indexes
36- Index(u'authors_id', authors_table.c.id)
37- Index(u'authors_display_name_id', authors_table.c.display_name,
38- authors_table.c.id)
39- Index(u'media_files_id', media_files_table.c.id)
40- Index(u'song_books_id', song_books_table.c.id)
41- Index(u'songs_id', songs_table.c.id)
42- Index(u'topics_id', topics_table.c.id)
43- Index(u'authors_songs_author', authors_songs_table.c.author_id,
44- authors_songs_table.c.song_id)
45- Index(u'authors_songs_song', authors_songs_table.c.song_id,
46- authors_songs_table.c.author_id)
47- Index(u'media_files_songs_file', media_files_songs_table.c.media_file_id,
48- media_files_songs_table.c.song_id)
49- Index(u'media_files_songs_song', media_files_songs_table.c.song_id,
50- media_files_songs_table.c.media_file_id)
51- Index(u'topics_song_topic', songs_topics_table.c.topic_id,
52- songs_topics_table.c.song_id)
53- Index(u'topics_song_song', songs_topics_table.c.song_id,
54- songs_topics_table.c.topic_id)
55-
56 mapper(Author, authors_table)
57 mapper(Book, song_books_table)
58 mapper(MediaFile, media_files_table)
59
60=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
61--- openlp/plugins/songs/lib/mediaitem.py 2011-05-28 19:38:19 +0000
62+++ openlp/plugins/songs/lib/mediaitem.py 2011-05-30 11:23:23 +0000
63@@ -27,6 +27,7 @@
64
65 import logging
66 import locale
67+import re
68
69 from PyQt4 import QtCore, QtGui
70 from sqlalchemy.sql import or_
71
72=== modified file 'openlp/plugins/songs/lib/xml.py'
73--- openlp/plugins/songs/lib/xml.py 2011-05-26 17:11:22 +0000
74+++ openlp/plugins/songs/lib/xml.py 2011-05-30 11:23:23 +0000
75@@ -514,7 +514,7 @@
76 ``song``
77 The song object.
78 """
79- song.song_book_id = 0
80+ song.song_book_id = None
81 song.song_number = u''
82 if hasattr(properties, u'songbooks'):
83 for songbook in properties.songbooks.songbook: