Skip to content
Snippets Groups Projects
Unverified Commit af6cb9b7 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Explicitly flush session for new objects.

Autocommit was removed in SQLAlchemy 1.3.
parent 4d0d2d8a
No related branches found
No related tags found
No related merge requests found
Pipeline #115 failed
......@@ -31,6 +31,8 @@ class GpxImporter(object):
if not waypoint:
logger.info('Creating new waypoint %s' % code)
waypoint = Waypoint(code=code)
session.add(waypoint)
session.flush()
# Update waypoint data
logger.info('Updating waypoint %s' % code)
......@@ -50,6 +52,8 @@ class GpxImporter(object):
else:
logger.info('Creating new cache listing for %s' % code)
listing = Listing(master_waypoint=waypoint, waypoints=[waypoint])
session.add(listing)
session.flush()
# Update listing data
logger.info('Updating listing for %s' % code)
......@@ -70,6 +74,8 @@ class GpxImporter(object):
owner_account = GeocacherAccount(name=owner_name,
platform_prefix=listing.platform_prefix)
Geocacher(accounts=[owner_account], master_account=owner_account)
session.add(owner_account)
session.flush()
listing.owner_account = owner_account
# Find or create geocache parent
......@@ -85,12 +91,16 @@ class GpxImporter(object):
if not other_waypoint:
logger.info('Creating new waypoint for %s' % other_code)
other_waypoint = Waypoint(code=other_code)
session.add(other_waypoint)
session.flush()
if other_waypoint.listing:
other_listing = other_waypoint.listing
else:
logger.info('Creating listing for %s' % other_code)
other_listing = Listing(master_waypoint=other_waypoint,
waypoints=[other_waypoint])
session.add(other_listing)
session.flush()
if other_listing.geocache:
listing.geocache = other_listing.geocache
else:
......@@ -115,6 +125,8 @@ class GpxImporter(object):
logger.info('Creating finder %s' % finder_name)
finder_account = GeocacherAccount(name=finder_name, platform_prefix=listing.platform_prefix)
Geocacher(accounts=[finder_account], master_account=finder_account)
session.add(finder_account)
session.flush()
# Get log data
date = dateutil.parser.parse(xml_get_text(log_node, 'groundspeak:date'))
......@@ -128,6 +140,8 @@ class GpxImporter(object):
if not log:
log = Log(date=date, type=type_, geocacher_account=finder_account,
listing=listing)
session.add(log)
session.flush()
log.text = text
elif waypoint.type.startswith('Waypoint|'):
# This is a sub-waypoint
......@@ -152,6 +166,8 @@ class GpxImporter(object):
if not parent_listing:
parent_listing = Listing(master_waypoint=parent_waypoint,
waypoints=[parent_waypoint])
session.add(parent_listing)
session.flush()
# Add waypoint
logger.info('Linking %s to %s' % (waypoint.code, parent_code))
......@@ -159,6 +175,7 @@ class GpxImporter(object):
# Add waypoint and all related objects to session
session.add(waypoint)
session.flush()
# Save
session.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment