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

Log duplicate issue numbers for a series and return all results #29

Merged
merged 1 commit into from
Aug 10, 2024
Merged
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
27 changes: 17 additions & 10 deletions gcd_talker/gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def fetch_issues_in_series(self, series_id: str) -> list[GenericMetadata]:
"ELSE NULL END, '\n') AS 'story_titles' "
"FROM gcd_issue "
"LEFT JOIN gcd_story ON gcd_story.issue_id = gcd_issue.id AND gcd_story.type_id = 19 "
"WHERE gcd_issue.series_id = ? "
"GROUP BY gcd_issue.number;",
"WHERE gcd_issue.series_id = ? AND gcd_issue.variant_of_id IS NULL "
"GROUP BY gcd_issue.id;",
[int(series_id)],
)
rows = cur.fetchall()
Expand Down Expand Up @@ -487,14 +487,14 @@ def fetch_issues_by_series_issue_num_and_year(
gcd_story.title END, '\n') AS 'story_titles'
FROM gcd_issue
LEFT JOIN gcd_story ON gcd_story.issue_id=gcd_issue.id AND gcd_story.type_id=19
WHERE gcd_issue.series_id=? """
WHERE gcd_issue.series_id=? AND gcd_issue.variant_of_id IS NULL """

sql_search_issues: str = "AND gcd_issue.number=? AND (gcd_issue.key_date LIKE ? OR gcd_issue.key_date='') "

sql_search_issues_nn: str = """AND (gcd_issue.number=? OR gcd_issue.number='[nn]') AND
(gcd_issue.key_date LIKE ? OR gcd_issue.key_date='') """

sql_search_group: str = "GROUP BY gcd_issue.number;"
sql_search_group: str = "GROUP BY gcd_issue.id;"

if self.nn_is_issue_one and issue_number == "1":
sql_search = sql_search_main + sql_search_issues_nn + sql_search_group
Expand Down Expand Up @@ -831,8 +831,7 @@ def _fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadat
# Find the id of the issue and pass it along

sql_query: str = ""
sql_base: str = """SELECT gcd_issue.id AS 'id'
FROM gcd_issue """
sql_base: str = "SELECT gcd_issue.id AS 'id' FROM gcd_issue "
sql_where: str = "WHERE gcd_issue.series_id=? AND gcd_issue.number=?"
sql_where_nn: str = "WHERE gcd_issue.series_id=? AND (gcd_issue.number=? OR gcd_issue.number='[nn]')"

Expand All @@ -851,10 +850,18 @@ def _fetch_issue_data(self, series_id: int, issue_number: str) -> GenericMetadat
sql_query,
[series_id, issue_number],
)
row = cur.fetchone()

if row["id"]:
return self._fetch_issue_data_by_issue_id(row["id"])
row = cur.fetchall()

# Expect one result however there are exception: "nn" for issue number and new volumes restarting issue
# number back to 1 are possible therefore, take the first result and log the remainder
if len(row) > 1:
logger.warning(
f"More than ONE issue found for: Series ID: {series_id}, Issue Number: "
f"{issue_number}. Using first result.\n"
f"All result IDs: {', '.join([str(i_id['id']) for i_id in row])}"
)
if row[0]["id"]:
return self._fetch_issue_data_by_issue_id(row[0]["id"])

except sqlite3.DataError as e:
logger.debug(f"DB data error: {e}")
Expand Down
Loading