From 3bed268d81fe5a950f4dd97ab052e91c5d0a27b9 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Tue, 14 Jul 2015 19:13:56 -0400 Subject: [PATCH] Fix use case for downgrading and adding a row with NULL --- eos/db/saveddata/fit.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index 24773a429..08cbef344 100644 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -55,8 +55,8 @@ class ProjectedFit(object): def __init__(self, sourceID, source_fit, amount=1, active=True): self.sourceID = sourceID self.source_fit = source_fit - self.amount = amount self.active = active + self.__amount = amount @reconstructor def init(self): @@ -66,6 +66,16 @@ class ProjectedFit(object): eos.db.saveddata_session.flush() eos.db.saveddata_session.refresh(self.victim_fit) + # We have a series of setters and getters here just in case someone + # downgrades and screws up the table with NULL values + @property + def amount(self): + return self.__amount or 1 + + @amount.setter + def amount(self, amount): + self.__amount = amount + Fit._Fit__projectedFits = association_proxy( "victimOf", # look at the victimOf association... "source_fit", # .. and return the source fits @@ -143,4 +153,8 @@ mapper(Fit, fits_table, } ) -mapper(ProjectedFit, projectedFits_table) +mapper(ProjectedFit, projectedFits_table, + properties = { + "_ProjectedFit__amount": projectedFits_table.c.amount, + } +)