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:
parent
5180925a46
commit
753eec3960
@ -87,12 +87,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.
|
||||
|
@ -21,34 +21,46 @@
|
||||
|
||||
# $Id$
|
||||
|
||||
from __future__ import with_statement, unicode_literals
|
||||
|
||||
import sys
|
||||
from ..lib.markertype import MarkerType
|
||||
from ..lib.tag import Tag
|
||||
import time
|
||||
import logging
|
||||
LOG = logging.getLogger(".upgrade")
|
||||
|
||||
from ..const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from ..constfunc import cuni, UNITYPE
|
||||
|
||||
"""
|
||||
methods to upgrade a database from version 13 to current version
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from __future__ import with_statement, unicode_literals
|
||||
import sys
|
||||
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
|
||||
from ..lib.markertype import MarkerType
|
||||
from ..lib.nameorigintype import NameOriginType
|
||||
from ..lib.tag import Tag
|
||||
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)
|
||||
from gramps.gui.dialog import (InfoDialog)
|
||||
|
||||
LOG = logging.getLogger(".upgrade")
|
||||
|
||||
def gramps_upgrade_16(self):
|
||||
"""Upgrade database from version 15 to 16. This upgrade converts all
|
||||
SourceRef child objects to Citation Primary objects.
|
||||
@ -587,7 +599,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()
|
||||
@ -820,7 +832,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)
|
||||
|
@ -78,6 +78,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,
|
||||
@ -1369,15 +1370,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
|
||||
|
||||
|
@ -742,7 +742,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:
|
||||
|
@ -1916,7 +1916,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 '
|
||||
|
Loading…
Reference in New Issue
Block a user