Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove flask upper pin 2 #432

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions invenio_vocabularies/datastreams/writers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2024 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -96,12 +97,13 @@ def write(self, stream_entry, *args, **kwargs):

try:
if self._insert:
try:
return StreamEntry(self._service.create(self._identity, entry))
except PIDAlreadyExists:
if not self._update:
raise WriterError([f"Vocabulary entry already exists: {entry}"])
return self._do_update(entry)
ret = StreamEntry(self._service.create(self._identity, entry))

# with that state management it is avoidable to check if pid
# exists and run into possible rollback problems
if self._update:
self._insert = False
return ret
elif self._update:
try:
return self._do_update(entry)
Expand All @@ -112,6 +114,8 @@ def write(self, stream_entry, *args, **kwargs):
["Writer wrongly configured to not insert and to not update"]
)

except PIDAlreadyExists:
raise WriterError([f"Vocabulary entry already exists: {entry}"])
except ValidationError as err:
raise WriterError([{"ValidationError": err.messages}])
except InvalidRelationValue as err:
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (C) 2020-2024 CERN.
# Copyright (C) 2021 TU Wien.
# Copyright (C) 2024 California Institute of Technology.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -81,7 +82,7 @@ def extra_entry_points():
@pytest.fixture(scope="module")
def app_config(app_config):
"""Mimic an instance's configuration."""
app_config["JSONSCHEMAS_HOST"] = "localhost"
app_config["JSONSCHEMAS_HOST"] = "not-used"
app_config["BABEL_DEFAULT_LOCALE"] = "en"
app_config["I18N_LANGUAGES"] = [("da", "Danish")]
app_config["RECORDS_REFRESOLVER_CLS"] = (
Expand Down
8 changes: 7 additions & 1 deletion tests/test_alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2021 TU Wien.
# Copyright (C) 2021 Northwestern University.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -46,7 +47,12 @@ def test_alembic(app, database):
raise pytest.skip("Upgrades are not supported on SQLite.")

# Check that this package's SQLAlchemy models have been properly registered
tables = [x.name for x in db.get_tables_for_bind()]
try:
# flask-sqlalchemy < 3.1.0
tables = [x.name for x in db.get_tables_for_bind()]
except AttributeError:
# flask-sqlalchemy >= 3.1.0
tables = [x for x in db.metadata.tables]
assert "vocabularies_metadata" in tables
assert "vocabularies_types" in tables
assert "vocabularies_schemes" in tables
Expand Down