Skip to content
Snippets Groups Projects
Commit 042932ea authored by Gottfried Gaisbauer's avatar Gottfried Gaisbauer
Browse files

fixed the commit bug. one does not have to add a already existing object in...

fixed the commit bug. one does not have to add a already existing object in the database to the session.
parent 19903ca4
No related branches found
No related tags found
No related merge requests found
......@@ -11,24 +11,25 @@ from libraries.database.database import db
class AuraDatabaseModel:
def store(self, commit=False):
obj_session = db.session.object_session(self)
if obj_session is not None:
obj_session.add(self)
if commit:
obj_session.commit()
db.session.add(self)
def store(self, add=False, commit=False):
#obj_session = db.session.object_session(self)
#if obj_session is not None:
# obj_session.add(self)
# if commit:
# obj_session.commit()
if add:
db.session.add(self)
if commit:
db.session.commit()
def delete(self, commit=False):
obj_session = db.session.object_session(self)
#obj_session = db.session.object_session(self)
if obj_session is not None:
obj_session.delete(self)
if commit:
obj_session.commit()
#if obj_session is not None:
# obj_session.delete(self)
# if commit:
# obj_session.commit()
db.session.delete(self)
if commit:
......@@ -41,6 +42,7 @@ class AuraDatabaseModel:
def recreate_db(systemexit = False):
manualschedule = Schedule()
manualschedule.schedule_id = 0
manualschedule.show_name = "Manual Show"
fallback_trackservice_schedule = TrackServiceSchedule()
fallback_trackservice_schedule.ts_schedule_id = 0
......@@ -140,8 +142,7 @@ class ScheduleEntry(db.Model, AuraDatabaseModel):
entry_end_unix = 0
programme_index = -1
ForeignKeyConstraint(['schedule_id'], ['schedule.schedule_id'])
schedule = relationship("Schedule", foreign_keys=[schedule_id])
schedule = relationship("Schedule", foreign_keys=[schedule_id], lazy="joined")
# ------------------------------------------------------------------------------------------ #
@staticmethod
......@@ -149,17 +150,17 @@ class ScheduleEntry(db.Model, AuraDatabaseModel):
# when deleting all entries, and fetching new programmes, the entries are stored and commited in the code.
# but sqlalchemy thinks somehow it is not commit and returns an empty set
print("WARNING: broadcasts.py This commit before SELECT is a BAND-AID & UGLY-HACK. Why the hell is there a transaction pending and not commited?")
db.session.commit()
#print("WARNING: broadcasts.py This commit before SELECT is a BAND-AID & UGLY-HACK. Why the hell is there a transaction pending and not commited?")
#db.session.commit()
# fetching all
# all_entries = ScheduleEntry.query.filter().all()
all_entries = db.session.query(ScheduleEntry).filter().all()
all_entries = db.session.query(ScheduleEntry).filter().order_by(ScheduleEntry.entry_start).all()
# BAND-AID debug output. The model and db session are different. crap
print("SELECT ALL ScheduleEntry.q.session == db.session?")
print("broadcasts.py SELECT ALL ScheduleEntry.q.session == db.session?")
print(ScheduleEntry.query.session == db.session)
print("SELECT ALL ScheduleEntry.q.s.conn == db.s.conn?")
print("broadcasts.py SELECT ALL ScheduleEntry.q.s.conn == db.s.conn?")
print(ScheduleEntry.query.session.connection() == db.session.connection())
cnt = 0
......@@ -176,7 +177,7 @@ class ScheduleEntry(db.Model, AuraDatabaseModel):
def select_next_manual_entry_num():
from sqlalchemy import func
# damn BAND-AID
db.session.commit()
#db.session.commit()
#subqry = db.session.query(func.max(ScheduleEntry.entry_num)).filter(ScheduleEntry.schedule_id = 0)
#qry = db.session.query(Data).filter(Data.user_id == user_id, Data.counter == subqry)
......@@ -197,7 +198,7 @@ class ScheduleEntry(db.Model, AuraDatabaseModel):
@staticmethod
def upcoming(datefrom=datetime.datetime.now()):
# damn BAND-AID
db.session.commit()
# db.session.commit()
upcomingtracks = db.session.query(ScheduleEntry).filter(ScheduleEntry.start > datefrom).all()
#upcomingtracks = ScheduleEntry.query.filter(ScheduleEntry.start > datefrom).all()
......@@ -207,7 +208,7 @@ class ScheduleEntry(db.Model, AuraDatabaseModel):
@staticmethod
def select_one(playlist_id, entry_num):
# damn BAND-AID
db.session.commit()
# db.session.commit()
one = db.session.query(ScheduleEntry).filter(ScheduleEntry.playlist_id == playlist_id, ScheduleEntry.entry_num == entry_num).first()
return one
......@@ -232,7 +233,7 @@ class TrackServiceSchedule(db.Model, AuraDatabaseModel):
@staticmethod
def select_one(schedule_id):
# damn BAND-AID
db.session.commit()
# db.session.commit()
return db.session.query(ScheduleEntry).filter(TrackServiceSchedule.schedule_id == schedule_id).first()
......
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