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

added subcommand to clean deleted relations for issue # 2444 #3224

Merged
merged 5 commits into from
Oct 23, 2023

Conversation

lujoh
Copy link
Contributor

@lujoh lujoh commented Oct 13, 2023

This adds the subcommand to clean deleted relations.
Fixes #2444

The pull request passes local test, but fails the GitHub Actions with this message:
nominatim/api/v1/helpers.py:52: error: Returning Any from function declared to return "tuple[int, int]" [no-any-return]

This error doesn't seem to be related to the topic of the pull request.
Please let me know how to proceed and if I need to make any changes.

@lonvia
Copy link
Member

lonvia commented Oct 16, 2023

This error doesn't seem to be related to the topic of the pull request.

That's the most recent version of mypy now correctly detecting a missing type declaration. I've just fixed this on master. Can you please rebase your change and force-push the result to your branch?

@lujoh lujoh force-pushed the clean-deleted-relations branch from f3c0cd1 to e9efef9 Compare October 16, 2023 15:31
Copy link
Member

@lonvia lonvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great already. Just some minor comments on the tests.

@@ -41,6 +41,8 @@ def add_args(self, parser: argparse.ArgumentParser) -> None:
help='Print performance analysis of the indexing process')
objs.add_argument('--collect-os-info', action="store_true",
help="Generate a report about the host system information")
objs.add_argument('--clean-deleted', action='store_true',
help='Clean up deleted relations')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can simply make the age a required argument to --clean-deleted. Then argparse ensures that the the argument is present and the code can be a lot simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback @lonvia! I wasn't able to make the age required directly because it was causing errors with the other commands that didn't include age. Instead I decided to raise a parser error right in the clicmd/admin.py file:
if not args.age: self.parser.error('Age is required for --clean-deleted command')
I moved the test for that into the cli/test_cmd_admin.py file. I think the solution is a bit cleaner, but if you know a way to make the argument required directly I'd be happy to switch to that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to give clean-deleted an argument:

objs.add_argument('--clean-deleted', action='store', metavar='AGE', help='...')

...

age = args.clean_deleted

...

But the current solution works as well. Just one tiny nitpick: simply do raise UsageError() instead of using self.parser.error(). Just for consistency with the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarifying lonvia. I misunderstood where you were going with that. I like your solution better. I've made the required changes for your comments.

END;
$$
LANGUAGE plpgsql;
""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try out if it is possible to use the original code here, so that we catch in the unit tests, when something breaks in the SQL? The following should work:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the function over and it seems to be working fine. I had to add a couple of extra tables and functions to the setup for the unit tests to cover everything in utils.sql.

temp_db_cursor.execute("""INSERT INTO placex (place_id, osm_id, osm_type, class, type, indexed_date, indexed_status)
VALUES(1, 100, 'N', 'boundary', 'administrative', current_date - INTERVAL '1 month', 1),
(2, 145, 'N', 'boundary', 'administrative', current_date - INTERVAL '1 month', 1),
(3, 175, 'R', 'landcover', 'grass', current_date - INTERVAL '1 month', 1)""")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give them different ages and then test that according to the age parameter really only a part of them is deleted.

@lonvia lonvia merged commit 6ad397d into osm-search:master Oct 23, 2023
8 checks passed
@lonvia
Copy link
Member

lonvia commented Oct 23, 2023

Thank you!

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.

Nominatim should regularly clean deleted relations
2 participants