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

This fixes errors introduced to browse given the changes I made to ba… #659

Merged
merged 1 commit into from
Jul 12, 2024
Merged
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
7 changes: 6 additions & 1 deletion browse/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from arxiv.base.urls import canonical_url, urlizer
from arxiv.base.filters import tidy_filesize
from arxiv.db import config_query_timing
from arxiv.db.models import configure_db
from flask import Flask
from flask_s3 import FlaskS3
# This gives the error on import
Expand Down Expand Up @@ -38,8 +39,12 @@ def create_web_app(**kwargs) -> Flask: # type: ignore
static_url_path=f'/static/browse/{settings.APP_VERSION}')
app.config.from_object(settings)

app.engine, app.latexml_engine = configure_db(settings) # type: ignore

Base(app)
config_query_timing(0.2, 8) # Log long SQL queries

# Log long SQL queries
config_query_timing(app.engine, 0.2, 8) # type: ignore
#Auth(app)

# routes
Expand Down
14 changes: 7 additions & 7 deletions browse/services/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from flask import current_app

from arxiv.db import session, engine
from arxiv.db import session
from arxiv.base.globals import get_application_config
from arxiv.document.metadata import DocMetadata
from dateutil.tz import gettz, tzutc
Expand All @@ -41,9 +41,9 @@
OrcidIds,
AuthorIds,
TapirUser,
PaperOwner,
t_arXiv_in_category,
t_arXiv_stats_hourly,
t_arXiv_paper_owners,
Metadata
)
from browse.services.listing import ListingItem
Expand Down Expand Up @@ -569,11 +569,11 @@ def get_orcid_by_user_id(user_id: int) -> Optional[str]:
@db_handle_error(db_logger=logger, default_return_val=[])
def get_articles_for_author(user_id: int) -> List[ListingItem]:
rows = session.execute(
select(Document, t_arXiv_paper_owners)
.filter(Document.document_id == t_arXiv_paper_owners.c.document_id)
.filter(t_arXiv_paper_owners.c.user_id == user_id)
.filter(t_arXiv_paper_owners.c.flag_author == 1)
.filter(t_arXiv_paper_owners.c.valid == 1)
select(Document, PaperOwner)
.filter(Document.document_id == PaperOwner.document_id)
.filter(PaperOwner.user_id == user_id)
.filter(PaperOwner.flag_author == 1)
.filter(PaperOwner.valid == 1)
.filter(Document.paper_id.notlike('test%'))
.order_by(Document.dated.desc())
).scalars().all()
Expand Down
106 changes: 103 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pg8000 = "^1.30.1"
lxml = "^4.9.2"
xmltodict = "^0.13.0"

arxiv-base = {git = "https://github.com/arXiv/arxiv-base.git", rev = "b673f9c0089b6191205b6143cf64aa7e1e6e0fce"}
arxiv-base = {git = "https://github.com/arXiv/arxiv-base.git", rev = "ac4f8cd17191cc19c9a8e1e572f270f8dcba5e46"}

flask = "^3.0.2"
google-cloud-compute = "^1.14.1"
Expand Down
22 changes: 11 additions & 11 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def foreign_key_check(engine, check_on:bool ):
with engine.connect() as conn:
conn.execute(text('SET FOREIGN_KEY_CHECKS = 0;'))

def _populate_latexml_test_data (db):
db.LaTeXMLBase.metadata.drop_all(bind=db.latexml_engine)
db.LaTeXMLBase.metadata.create_all(bind=db.latexml_engine)
def _populate_latexml_test_data (db, latexml_engine: Engine):
db.LaTeXMLBase.metadata.drop_all(bind=latexml_engine)
db.LaTeXMLBase.metadata.create_all(bind=latexml_engine)
db.session.commit()

dt = datetime(2024, 1, 30, 15, 0, 0)
Expand Down Expand Up @@ -116,14 +116,14 @@ def _populate_latexml_test_data (db):
db.session.add(db.models.DBLaTeXMLDocuments(**doc))
db.session.commit()

def populate_test_database(drop_and_create: bool, db):
def populate_test_database(drop_and_create: bool, db, engine: Engine, latexml_engine: Engine):
"""Initialize the browse tables."""
if drop_and_create:
foreign_key_check(db.engine, False)
db.metadata.drop_all(bind=db.engine)
foreign_key_check(engine, False)
db.metadata.drop_all(bind=engine)
db.session.commit()
foreign_key_check(db.engine, True)
db.metadata.create_all(bind=db.engine)
foreign_key_check(engine, True)
db.metadata.create_all(bind=engine)
db.session.commit()

# Member institution data
Expand Down Expand Up @@ -185,13 +185,13 @@ def populate_test_database(drop_and_create: bool, db):
db.session.add(inst_other_ip)

sql_files: List[str] = glob.glob('./tests/data/db/sql/*.sql')
foreign_key_check(db.engine, False)
execute_sql_files(sql_files, db.engine)
foreign_key_check(engine, False)
execute_sql_files(sql_files, engine)
db.session.commit()

print ("FIRST METADATA:")
print (db.session.query(Metadata).first())

_populate_latexml_test_data(db)
_populate_latexml_test_data(db, latexml_engine)

ABS_FILES = path_of_for_test('data/abs_files')
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def loaded_db():
with app.app_context():
from arxiv import db
from . import populate_test_database
populate_test_database(True, db)
populate_test_database(True, db, app.engine, app.latexml_engine) # type: ignore


@pytest.fixture(scope='session')
Expand Down
Binary file added tests/data/latexmldb.db
Binary file not shown.
Loading