7582: Cannot remove a primary object having a new created backreference

This removes the create_id method from gen/db/write.py, since
after a recent "from __future__ import unicode_literals" (there)
it started producing unicode.  Instead the create_id method in
gen/utils/id.py is used, as its code is essentially identical,
in use in many other places -- and does not produce unicode.
This commit is contained in:
Paul Franklin 2014-05-03 07:00:51 -07:00
parent 92f5a5e36c
commit 2a608151c2
5 changed files with 40 additions and 37 deletions

View File

@ -97,12 +97,6 @@ class DbReadBase(object):
"""
raise NotImplementedError
def create_id(self):
"""
Create an id
"""
raise NotImplementedError
def db_has_bm_changes(self):
"""
Return whethere there were bookmark changes during the session.

View File

@ -19,40 +19,52 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from __future__ import with_statement, unicode_literals
import sys
import os
import re
from ..lib.markertype import MarkerType
from ..lib.tag import Tag
from ..lib.place import Place
from ..lib.placeref import PlaceRef
from ..lib.placetype import PlaceType
from ..utils.file import create_checksum
import time
import logging
LOG = logging.getLogger(".upgrade")
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from ..constfunc import cuni, UNITYPE, handle2internal
"""
methods to upgrade a database from version 13 to current version
"""
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
from __future__ import with_statement, unicode_literals
import sys
import os
import re
import time
import logging
from ..config import config
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
from bsddb3 import db
else:
from bsddb import db
from . import BSDDBTxn
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from ..constfunc import cuni, UNITYPE, handle2internal
from ..lib.markertype import MarkerType
from ..lib.nameorigintype import NameOriginType
from ..lib.place import Place
from ..lib.placeref import PlaceRef
from ..lib.placetype import PlaceType
from ..lib.tag import Tag
from ..utils.file import create_checksum
from ..utils.id import create_id
from . import BSDDBTxn
from .write import _mkname, SURNAMES
from .dbconst import (PERSON_KEY, FAMILY_KEY, EVENT_KEY,
MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, SOURCE_KEY)
MEDIA_KEY, PLACE_KEY, REPOSITORY_KEY, SOURCE_KEY)
from gramps.gui.dialog import (InfoDialog)
LOG = logging.getLogger(".upgrade")
def gramps_upgrade_17(self):
"""
Upgrade database from version 16 to 17.
@ -262,7 +274,7 @@ def get_location(loc):
return location
def add_place(self, name, level, parent, title):
handle = self.create_id()
handle = create_id()
place = Place()
place.handle = handle
self.max_id += 1
@ -831,7 +843,7 @@ def convert_source_list_to_citation_list_16(self, source_list):
citation_list = []
for source in source_list:
(date, private, note_list, confidence, ref, page) = source
new_handle = self.create_id()
new_handle = create_id()
new_media_list = []
new_data_map = {}
new_change = time.time()
@ -1066,7 +1078,7 @@ def convert_marker(self, marker_field):
if tag_name != '':
if tag_name not in self.tags:
tag = Tag()
handle = self.create_id()
handle = create_id()
tag.set_handle(handle)
tag.set_change_time(time.time())
tag.set_name(tag_name)

View File

@ -85,6 +85,7 @@ from . import (DbBsddbRead, DbWriteBase, BSDDBTxn,
from .dbconst import *
from ..utils.callback import Callback
from ..utils.cast import conv_dbstr_to_unicode
from ..utils.id import create_id
from ..updatecallback import UpdateCallback
from ..errors import DbError
from ..constfunc import (win, conv_to_unicode, cuni, UNITYPE, handle2internal,
@ -1552,15 +1553,11 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
except IOError:
pass
def create_id(self):
return "%08x%08x" % ( int(time.time()*10000),
self.rand.randint(0, maxsize))
def __add_object(self, obj, transaction, find_next_func, commit_func):
if find_next_func and not obj.gramps_id:
obj.gramps_id = find_next_func()
if not obj.handle:
obj.handle = self.create_id()
obj.handle = create_id()
commit_func(obj, transaction)
return obj.handle

View File

@ -747,7 +747,7 @@ class CSVParser(object):
id_ = self.db.fid2user_format(family_ref[1:-1])
family.set_gramps_id(id_)
# add it:
family.set_handle(self.db.create_id())
family.set_handle(create_id())
if self.default_tag:
family.add_tag(self.default_tag.handle)
if husband:

View File

@ -1952,7 +1952,7 @@ class CheckIntegrity(object):
new_citation.set_confidence_level(sourceref[3])
new_citation.set_reference_handle(sourceref[4])
new_citation.set_page(sourceref[5])
citation_handle = Utils.create_id()
citation_handle = create_id()
new_citation.set_handle(citation_handle)
self.replaced_sourceref.append(handle)
logging.warning(' FAIL: the source "%s" has a media '