def insert(cls, *args, **kwargs): if is_deprecated_model(cls): raise Exception("Attempt to write to deprecated model %s" % cls) query = super(ReadReplicaSupportedModel, cls).insert(*args, **kwargs) if cls._in_readonly_mode(): raise ReadOnlyModeException() return query
def raw(cls, *args, **kwargs): query = super(ReadReplicaSupportedModel, cls).raw(*args, **kwargs) if query._sql.lower().startswith("select "): query._database = cls._select_database() elif cls._in_readonly_mode(): raise ReadOnlyModeException() elif query._sql.lower().startswith("insert "): if is_deprecated_model(cls): raise Exception("Attempt to write to deprecated model %s" % cls) return query
def find_models_missing_data(): # As a sanity check we are going to make sure that all db tables have some data, unless explicitly # whitelisted. models_missing_data = set() for one_model in all_models: if one_model in appr_classes: continue try: one_model.select().get() except one_model.DoesNotExist: if one_model.__name__ not in WHITELISTED_EMPTY_MODELS and not is_deprecated_model( one_model): models_missing_data.add(one_model.__name__) return models_missing_data