Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unique_constraint(env):
"""
Test that we are prevented from recreating existing objects
"""
with pytest.raises(peewee.IntegrityError):
Namespace.create(namespace='system')
with pytest.raises(peewee.IntegrityError):
FlowModel.create(namespace=env['ns']['test'], name='f1', version=1)
with pytest.raises(peewee.IntegrityError):
TaskModel.create(name='t1', flow=env['f']['f1'])
if current_user != user and not current_user.is_admin:
return permission_denied("Sorry, you may not edit this user.")
update_user(user, request.form, current_user)
# save:
try:
user.save()
if userid == -1:
flash('New user created.')
return redirect(url_for('user_edit', userid=user.id))
else:
flash('Saved')
except peewee.IntegrityError as err:
flash('Cannot Save:' + str(err))
elif request.method == 'DELETE':
if not current_user.is_admin:
return 'Sorry, only admins can delete users', 403
if user.id == current_user.id:
return 'Sorry! You cannot delete yourself!', 403
user.delete_instance(recursive=True)
return 'User: %s deleted. (And all their posts)' % user.displayname
users_posts = Post.select().where(Post.author == user) \
.order_by(Post.write_date.desc()) \
.limit(10)
# Create new client
obj = self.manager.create(
key=player['key']
)
# Update newly created object
self.manager.update(
obj, player,
fetch=fetch,
match=match,
filtered_exception=filtered_exception
)
return obj
except (apsw.ConstraintError, peewee.IntegrityError):
# Return existing user
obj = self(player)
if fetch or match:
# Update existing `User`
self.manager.update(
obj, player,
fetch=fetch,
match=match,
filtered_exception=filtered_exception
)
return obj
def store_repository_action_count(repository, day, action_count):
"""
Stores the action count for a repository for a specific day.
Returns False if the repository already has an entry for the specified day.
"""
try:
RepositoryActionCount.create(repository=repository, date=day, count=action_count)
return True
except IntegrityError:
logger.debug("Count already written for repository %s", repository.id)
return False
# Create new session
obj = self.manager.create(
rating_key=to_integer(info.get('ratingKey')),
session_key=self.build_session_key(session_key),
state='create'
)
# Update newly created object
self.manager.update(obj, info, fetch)
# Update active sessions
ModuleManager['sessions'].on_created(obj)
return obj
except (apsw.ConstraintError, peewee.IntegrityError):
# Return existing object
return self(info)
async def get_or_create(self, **kwargs):
defaults = kwargs.pop('defaults', {})
query = self.model_class.select().bind(self.database)
for field, value in kwargs.items():
query = query.where(getattr(self.model_class, field) == value)
try:
result = await query.get(), False
except self.model_class.DoesNotExist:
try:
if defaults:
kwargs.update(defaults)
result = await self.create(**kwargs), True
except IntegrityError as exc:
try:
result = await query.get(), False
except self.model_class.DoesNotExist:
raise exc
return result
_chunk_delete_all(repo, RepositoryAuthorizedEmail, force=force)
# Delete any marker rows for the repository.
DeletedRepository.delete().where(DeletedRepository.repository == repo).execute()
# Delete the rest of the repository metadata.
try:
# Make sure the repository still exists.
fetched = Repository.get(id=repo.id)
except Repository.DoesNotExist:
return False
try:
fetched.delete_instance(recursive=True, delete_nullable=False, force=force)
return True
except IntegrityError:
return False
def series_add():
from bard.tasks.series import update_series
provider_id = request.values.get("provider_id")
series_info = providers.info.get_series_by_provider_id(provider_id)
# Attempt to link in provider_ids from non-search providers
providers.info.link_series_providers(series_info)
if series_info:
series = None
try:
series = Series.from_metadata(series_info)
except IntegrityError:
flash(
"{} is already a tracked series".format(series_info.name),
category="error",
)
else:
update_series(series)
flash(
"Added {} to tracked series".format(series_info.name),
category="success",
)
return redirect("/series/{}".format(series.id))
else:
flash("Unknown Provider ID ({})".format(provider_id), category="error")
return redirect("/series")
Produto.estoque_maximo: self.estoqueMaximo,
Produto.valor_compra: self.valorCompra,
Produto.valor_unitario: self.valorUnitario,
Produto.valor_atacado: self.valorAtacado,
Produto.qtde_atacado: self.qtdeAtacado,
Produto.obs: self.obsProduto
}
)
# Executando a Query
row.execute()
# Fechando a Conexao
Conexao().dbhandler.close()
except peewee.IntegrityError as err:
print(err)
pass