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
92f5a5e36c
commit
2a608151c2
@ -97,12 +97,6 @@ class DbReadBase(object):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def create_id(self):
|
|
||||||
"""
|
|
||||||
Create an id
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def db_has_bm_changes(self):
|
def db_has_bm_changes(self):
|
||||||
"""
|
"""
|
||||||
Return whethere there were bookmark changes during the session.
|
Return whethere there were bookmark changes during the session.
|
||||||
|
@ -19,40 +19,52 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 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
|
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
|
from ..config import config
|
||||||
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
|
if config.get('preferences.use-bsddb3') or sys.version_info[0] >= 3:
|
||||||
from bsddb3 import db
|
from bsddb3 import db
|
||||||
else:
|
else:
|
||||||
from bsddb import db
|
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.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 .write import _mkname, SURNAMES
|
||||||
from .dbconst import (PERSON_KEY, FAMILY_KEY, EVENT_KEY,
|
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)
|
from gramps.gui.dialog import (InfoDialog)
|
||||||
|
|
||||||
|
LOG = logging.getLogger(".upgrade")
|
||||||
|
|
||||||
def gramps_upgrade_17(self):
|
def gramps_upgrade_17(self):
|
||||||
"""
|
"""
|
||||||
Upgrade database from version 16 to 17.
|
Upgrade database from version 16 to 17.
|
||||||
@ -262,7 +274,7 @@ def get_location(loc):
|
|||||||
return location
|
return location
|
||||||
|
|
||||||
def add_place(self, name, level, parent, title):
|
def add_place(self, name, level, parent, title):
|
||||||
handle = self.create_id()
|
handle = create_id()
|
||||||
place = Place()
|
place = Place()
|
||||||
place.handle = handle
|
place.handle = handle
|
||||||
self.max_id += 1
|
self.max_id += 1
|
||||||
@ -831,7 +843,7 @@ def convert_source_list_to_citation_list_16(self, source_list):
|
|||||||
citation_list = []
|
citation_list = []
|
||||||
for source in source_list:
|
for source in source_list:
|
||||||
(date, private, note_list, confidence, ref, page) = source
|
(date, private, note_list, confidence, ref, page) = source
|
||||||
new_handle = self.create_id()
|
new_handle = create_id()
|
||||||
new_media_list = []
|
new_media_list = []
|
||||||
new_data_map = {}
|
new_data_map = {}
|
||||||
new_change = time.time()
|
new_change = time.time()
|
||||||
@ -1066,7 +1078,7 @@ def convert_marker(self, marker_field):
|
|||||||
if tag_name != '':
|
if tag_name != '':
|
||||||
if tag_name not in self.tags:
|
if tag_name not in self.tags:
|
||||||
tag = Tag()
|
tag = Tag()
|
||||||
handle = self.create_id()
|
handle = create_id()
|
||||||
tag.set_handle(handle)
|
tag.set_handle(handle)
|
||||||
tag.set_change_time(time.time())
|
tag.set_change_time(time.time())
|
||||||
tag.set_name(tag_name)
|
tag.set_name(tag_name)
|
||||||
|
@ -85,6 +85,7 @@ from . import (DbBsddbRead, DbWriteBase, BSDDBTxn,
|
|||||||
from .dbconst import *
|
from .dbconst import *
|
||||||
from ..utils.callback import Callback
|
from ..utils.callback import Callback
|
||||||
from ..utils.cast import conv_dbstr_to_unicode
|
from ..utils.cast import conv_dbstr_to_unicode
|
||||||
|
from ..utils.id import create_id
|
||||||
from ..updatecallback import UpdateCallback
|
from ..updatecallback import UpdateCallback
|
||||||
from ..errors import DbError
|
from ..errors import DbError
|
||||||
from ..constfunc import (win, conv_to_unicode, cuni, UNITYPE, handle2internal,
|
from ..constfunc import (win, conv_to_unicode, cuni, UNITYPE, handle2internal,
|
||||||
@ -1552,15 +1553,11 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
|||||||
except IOError:
|
except IOError:
|
||||||
pass
|
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):
|
def __add_object(self, obj, transaction, find_next_func, commit_func):
|
||||||
if find_next_func and not obj.gramps_id:
|
if find_next_func and not obj.gramps_id:
|
||||||
obj.gramps_id = find_next_func()
|
obj.gramps_id = find_next_func()
|
||||||
if not obj.handle:
|
if not obj.handle:
|
||||||
obj.handle = self.create_id()
|
obj.handle = create_id()
|
||||||
commit_func(obj, transaction)
|
commit_func(obj, transaction)
|
||||||
return obj.handle
|
return obj.handle
|
||||||
|
|
||||||
|
@ -747,7 +747,7 @@ class CSVParser(object):
|
|||||||
id_ = self.db.fid2user_format(family_ref[1:-1])
|
id_ = self.db.fid2user_format(family_ref[1:-1])
|
||||||
family.set_gramps_id(id_)
|
family.set_gramps_id(id_)
|
||||||
# add it:
|
# add it:
|
||||||
family.set_handle(self.db.create_id())
|
family.set_handle(create_id())
|
||||||
if self.default_tag:
|
if self.default_tag:
|
||||||
family.add_tag(self.default_tag.handle)
|
family.add_tag(self.default_tag.handle)
|
||||||
if husband:
|
if husband:
|
||||||
|
@ -1952,7 +1952,7 @@ class CheckIntegrity(object):
|
|||||||
new_citation.set_confidence_level(sourceref[3])
|
new_citation.set_confidence_level(sourceref[3])
|
||||||
new_citation.set_reference_handle(sourceref[4])
|
new_citation.set_reference_handle(sourceref[4])
|
||||||
new_citation.set_page(sourceref[5])
|
new_citation.set_page(sourceref[5])
|
||||||
citation_handle = Utils.create_id()
|
citation_handle = create_id()
|
||||||
new_citation.set_handle(citation_handle)
|
new_citation.set_handle(citation_handle)
|
||||||
self.replaced_sourceref.append(handle)
|
self.replaced_sourceref.append(handle)
|
||||||
logging.warning(' FAIL: the source "%s" has a media '
|
logging.warning(' FAIL: the source "%s" has a media '
|
||||||
|
Loading…
x
Reference in New Issue
Block a user