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

Feature/ogc 508 replace elastic search by postgres v2 #1357

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

Tschuppi81
Copy link
Contributor

Please fill in the commit message below and work through the checklist. You can delete parts that are not needed, e.g. the optional description, the link to a ticket or irrelevant options of the checklist.

Commit message

:

TYPE: <Feature|Bugfix>
LINK:
HINT:

Checklist

  • I have performed a self-review of my code
  • I considered adding a reviewer
  • I have added an upgrade hint such as data migration commands to be run
  • I have updated the PO files
  • I have added new modules to the docs
  • I made changes/features for both org and town6
  • I have updated the election_day API docs
  • I have tested my code thoroughly by hand
    • I have tested styling changes/features on different browsers
    • I have tested javascript changes/features on different browsers
    • I have tested database upgrades
    • I have tested sending mails
    • I have tested building the documentation
  • I have added tests for my changes/features
    • I am using freezegun for tests depending on date and times
    • I considered using browser tests für javascript changes/features
    • I have added/updated jest tests for d3rendering (election_day, swissvotes)

Copy link

linear bot commented Jun 5, 2024

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 89.46078% with 43 lines in your changes missing coverage. Please review.

Project coverage is 89.46%. Comparing base (93f6678) to head (0167dd6).
Report is 55 commits behind head on master.

Files with missing lines Patch % Lines
src/onegov/org/models/search.py 87.02% 17 Missing ⚠️
src/onegov/org/views/search.py 68.18% 7 Missing ⚠️
src/onegov/agency/views/search.py 50.00% 4 Missing ⚠️
src/onegov/fsi/models/course_event.py 63.63% 4 Missing ⚠️
src/onegov/agency/models/person.py 81.81% 2 Missing ⚠️
src/onegov/fsi/models/course_attendee.py 85.71% 2 Missing ⚠️
src/onegov/fsi/views/search.py 80.00% 2 Missing ⚠️
src/onegov/feriennet/models/activity.py 85.71% 1 Missing ⚠️
src/onegov/landsgemeinde/views/search.py 80.00% 1 Missing ⚠️
src/onegov/search/cli.py 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
Files with missing lines Coverage Δ
src/onegov/activity/models/attendee.py 98.66% <100.00%> (+0.03%) ⬆️
src/onegov/agency/models/agency.py 96.15% <100.00%> (+0.26%) ⬆️
src/onegov/agency/models/membership.py 100.00% <100.00%> (ø)
src/onegov/core/elements.py 97.27% <100.00%> (+0.02%) ⬆️
src/onegov/directory/models/directory.py 93.44% <100.00%> (+0.36%) ⬆️
src/onegov/directory/models/directory_entry.py 98.50% <100.00%> (+3.26%) ⬆️
src/onegov/event/models/event.py 95.37% <100.00%> (+0.02%) ⬆️
src/onegov/event/models/occurrence.py 100.00% <100.00%> (ø)
src/onegov/file/models/file.py 93.79% <100.00%> (ø)
src/onegov/form/models/submission.py 95.29% <100.00%> (ø)
... and 44 more

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93f6678...0167dd6. Read the comment docs.

@Tschuppi81
Copy link
Contributor Author

@Daverball I am working on the tests in test_views_search.py and can't make them pass. I narrowed the issue down to the hybrid_property resp. expression of GeneralFile and News.
While debugging for News I see that es_public is True for all the three elements in the DB. Same for access and published. Once I apply the query.filter(model.es_public == True) no elements are left.
Screenshot from 2024-10-14 06-29-53
Any idea why my filter statement or my hybrid expression does not work?

@Daverball
Copy link
Member

@Daverball I am working on the tests in test_views_search.py and can't make them pass. I narrowed the issue down to the hybrid_property resp. expression of GeneralFile and News. While debugging for News I see that es_public is True for all the three elements in the DB. Same for access and published. Once I apply the query.filter(model.es_public == True) no elements are left. Screenshot from 2024-10-14 06-29-53 Any idea why my filter statement or my hybrid expression does not work?

You're relying a lot on implicit type conversions here and hoping that SQLAlchemy is doing the right thing for you. You could try .is_(True) rather than == True, which is the recommended way for boolean and none checks in SQLAlchemy anyways. Although you can probably just filter on the column itself, since a boolean column can be used as a filter so filter(model.es_public) should technically work as well.

Either way to properly debug this, you would have to look at the final SQL statement SQLAlchemy generates for you. Sometimes you will just have to manually define an @{property_name}.expression for hybrid properties to get something correct. There's already several hybrid properties that define a manual expression, like published.

@Daverball
Copy link
Member

Also as a side note query.count is quite inefficient for checking whether or not you have any results, since Postgres will have to find and count all the entries. It's usually better to do if session.query(query.exists()).scalar(): which will create an EXISTS subquery, which only has to find a single row that satisfies the predicate before returning a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants