Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_event_by_number(number: str) -> Optional[models.Event]:
try:
return models.Event.get(models.Event.primary_number == number)
except peewee.DoesNotExist:
return None
def _get_experiment(self, experiment_id):
if experiment_id in self.caches:
return self.caches[experiment_id], None
try:
experiment = Experiment.get_by_id(experiment_id)
self.caches[experiment_id] = experiment
except peewee.DoesNotExist:
return False, minetorch_pb2.StandardResponse(
status=1,
message='Could not find experiment, abort'
)
return experiment, None
def listaStatusEntrega(self):
try:
# Query
self.query = StatusEntrega.select()
# Fechando a Conexao
Conexao().dbhandler.close()
except peewee.DoesNotExist as err:
print(err)
def check_db_schema_version():
""" Ensure DB schema is correct version. Drop tables if not. """
db_schema_version = None
try:
db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
printdbg("[info]: Can't get DB_SCHEMA_VERSION...")
printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
if (SCHEMA_VERSION != db_schema_version):
printdbg("[info]: Schema version mis-match. Syncing tables.")
try:
existing_table_names = db.get_tables()
existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
if (existing_models):
printdbg("[info]: Dropping tables...")
db.drop_tables(existing_models, safe=False, cascade=False)
except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
print("[error] Could not drop tables: %s" % e)
# - https://live.48.cn/Index/invedio/club/3/id/1750
# - https://live.48.cn/Index/invedio/club/3/id/2451
# Both have id 5bd81e5a0cf27e320898288b (which looks like a
# MongoDB ObjectID). How they managed to create the collision,
# I can't even imagine.
if canon_id == "5bd81e5a0cf27e320898288b":
# Known collision, can't do anything about it.
pass
else:
try:
existing = PerfVOD.get(canon_id=canon_id)
if existing.start_time != start_time:
raise UnretriableException(
f"{url}: conflict with {existing.l4c_url}"
)
except peewee.DoesNotExist:
raise e
with seen_urls_lock:
seen_urls.add(url)
self.idCliente = busca.id_cliente
self.dataEmissao = busca.data_emissao
self.prazoEntrega = busca.prazo_entrega
self.dataEntrega = busca.data_entrega
self.categoria = busca.categoria
self.desconto = busca.desconto
self.frete = busca.frete
self.valorTotal = busca.valor_total
self.valorRecebido = busca.valor_recebido
self.valorPendente = busca.valor_pendente
self.idStatusEntrega = busca.entrega.id
self.statusEntrega = busca.entrega.status_entrega
self.idStatusPagamento = busca.pagamento.id
self.statusPagamento = busca.pagamento.status_pagamento
except peewee.DoesNotExist as err:
print(err)
def fetchToken(self, token):
if token is None:
abort(400, message="token is required")
expired = round(time.time()) - ModelToken.EXPIRE_IN
try:
storedToken = ModelToken.get(
ModelToken.token_value == token,
ModelToken.date_created > expired
)
except peewee.DoesNotExist:
abort(404, message="token does not exist")
return storedToken
# Now let's make sure there isn't a domain collision
# Pop off first sublabel
sublabels.pop(0)
while len(sublabels) >= 1:
try:
d = self.get_domain_object().get(
Domain.domain == '.'.join(sublabels) + '.' + domain.domain
)
if d.domain_id == domain.domain_id:
# Should not get here, but just in case
# domain name and id match, done checking
return domain
else:
# collision!
return False
except DoesNotExist:
sublabels.pop(0)
if len(sublabels) is 0:
# Done checking, no collisions
return domain
else:
# no collisions yet, keep checking
continue
# Should not ever get here, but just in case
return False
def check_password(login, password):
try:
user = Users.check(login, password)
except DoesNotExist:
raise LookupError('User not found')
return user
def lastIdStatusPagamento(self):
try:
# Query
ultimo = (StatusPagamento.select().order_by(
StatusPagamento.id.desc()).get())
self.id = ultimo.id + 1
# Fechando a conexao
Conexao().dbhandler.close()
except peewee.DoesNotExist:
self.id = 1
return self.id