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

csv import and export fixes #3135

Merged
merged 9 commits into from
Aug 23, 2024
Merged

csv import and export fixes #3135

merged 9 commits into from
Aug 23, 2024

Conversation

hughrun
Copy link
Contributor

@hughrun hughrun commented Nov 25, 2023

Adds shelved and published dates for books and their imported reviews. Provides option to create new (custom) shelves when importing books.

fixes #3004
fixes #2411

@bookwyrm-social/code-review I'm looking for some clues as to why my tests fail when run sequentially but pass when run individually.

Adds shelved and published dates for books and their imported reviews.
Provides option to create new (custom) shelves when importing books.

fixes bookwyrm-social#3004
fixes bookwyrm-social#2846
fixes bookwyrm-social#2666
fixes bookwyrm-social#2411
@mouse-reeve
Copy link
Member

I'm not sure how to handle the merge conflicts on this one

@hughrun hughrun closed this Jan 14, 2024
@hughrun hughrun deleted the csv branch January 14, 2024 01:12
@hughrun hughrun restored the csv branch January 14, 2024 06:24
@hughrun hughrun reopened this Jan 14, 2024
@mouse-reeve
Copy link
Member

I wasn't sure how to resolve the merge conflicts on this

@hughrun
Copy link
Contributor Author

hughrun commented Apr 25, 2024

yeah I got distracted with other things, I need to come back to this.

@hughrun
Copy link
Contributor Author

hughrun commented Jul 22, 2024

There's something wrong with my tests here (test_create_new_shelf and test_handle_imported_book_review) - they pass when run in isolation but not when running the whole TestCase. Any ideas @bookwyrm-social/code-review ?

@dato
Copy link
Contributor

dato commented Jul 22, 2024

Hello @hughrun!

I took a look at the failures, here's the root cause (fwiw took a while to figure out!):

The __init__ method of BookwyrmBooksImporter is used to extend the row_mappings_guesses attribute:

def __init__(self, *args: Any, **kwargs: Any):
self.row_mappings_guesses.append(("shelf_name", ["shelf_name"]))
super().__init__(*args, **kwargs)

But row_mappings_guesses is a class level attribute, not instance level; so what happens is that the pair ("shelf_name", ["shelf_name"]) is appended once per created object.

The tests fail when such __init__ runs more than once (more than one importer created), because the duplication results in shelf_name=None in the import item.

To fix the issue, you can remove the __init__ method in favor of, for example:

class BookwyrmBooksImporter(Importer):
    # ...
    row_mappings_guesses = Importer.row_mappings_guesses + [
        ("shelf_name", ["shelf_name"]),
    ]

to avoid the bogus duplication.

- change class attribute to instance attribute for mappings
- remove comment from test
- order import retry jobs in generic importer test

This last change seems innocuous but I may be missing something more fundamental  - it was otherwise failing when multiple tests are run, I think because running tests in parallel led to import jobs getting out of order?
@hughrun hughrun marked this pull request as ready for review July 27, 2024 03:22
@hughrun
Copy link
Contributor Author

hughrun commented Jul 27, 2024

Ok a couple of things here:

  1. I amended the test for retry jobs in bookwyrm/tests/importers/test_importer.py to order the jobs, because they were running in the reverse order when running multiple tests (but not a single test). My assumption is that this happened because pylint runs tests in parallel, and that ultimately it doesn't matter which order they run in, but it may have been indicating an actual problem - so some eyes on that would be helpful.
  2. All tests pass locally, but there seems to be some kind of issue with the GitHub runners. Not sure what I can do about that.

@dato thanks for your advice.

@mouse-reeve
Copy link
Member

I think this just needs a merge migration in order to be ready to go

@hughrun
Copy link
Contributor Author

hughrun commented Aug 7, 2024

Ok there seems to be a conflict in the tests (causing some imports to finish out of order) because I'm using the same books as in generic.csv. Presumably this is because tests run in parallel? I'll adjust the test data to fix this.

- fix tests
- revert change to GenericImporter tests
- import the review name
- add extra properties to ImportItem
@hughrun
Copy link
Contributor Author

hughrun commented Aug 10, 2024

@bookwyrm-social/code-review I think this is ready.

@mouse-reeve
Copy link
Member

Worked neatly for me! Thank you so much

@mouse-reeve mouse-reeve merged commit 413c26b into bookwyrm-social:main Aug 23, 2024
10 checks passed
@eldang
Copy link

eldang commented Aug 23, 2024

Thank you! I'm excited for when this makes out to instances in the wild.

@mouse-reeve
Copy link
Member

It seems like since merging this tests have been failing on new pull requests:

FAILED bookwyrm/tests/importers/test_importer.py::GenericImporter::test_create_job - AssertionError: 1 != 0

@hughrun
Copy link
Contributor Author

hughrun commented Aug 25, 2024

ugggghhhh that's the error I was getting originally, I thought I'd fixed it by not using the same books to test importing.

@mouse-reeve from my own troubleshooting on this it seems that the tests sometimes return books in a slightly different order, which is what leads to this assertion error.

All tests pass individually but not together, so there's something I'm not understanding that leads to this difference: perhaps tests running concurrently leading to celery tasks returning in different orders?

@mouse-reeve
Copy link
Member

Ah how frustrating! I tried re-writing that test to ignore the order of the items: #3419. It's hacky, but if it works...?

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.

Importing books from another Bookwyrm instance fails Generic CSV import
4 participants