I have a settings model in sqlalchemy with flask
class Settings(Base):
__tablename__ = 'setting'
settings = db.Column(db.JSON(), nullable=False, default={'connections': []})
def serializable(self):
return {'settings': self.settings}
def __repr__(self):
return f'<Settings for {self.project} id: {self.id}>'
When I try to update settings
field in the Settings
table it just does not stick.
@settingsBP.route('/delete/<connection_name>', methods=['DELETE'])
def delete(connection_name):
settings = Settings.query.first()
settings_copy = settings.settings
for i, v in enumerate(settings_copy['connections']):
if v['database'] == connection_name:
del settings_copy['connections'][i]
break
settings.settings = settings_copy
db.session.commit()
return jsonify(settings_copy)
If I print settings_copy
it prints correctly. But the settings.settings
isn't saving any of the changes. I tried modifying the settings.settings
directly but that did not work.