Skip to content

Commit

Permalink
Merge pull request #7009 from drew2a/fix/6986
Browse files Browse the repository at this point in the history
Add Null check for `entry.tag_processor_version`
  • Loading branch information
drew2a authored Aug 18, 2022
2 parents c9f2217 + 8e155ff commit 365b4f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def extract_tags(self, entry):
if not is_torrent or not self.tag_rules_processor:
return

is_auto_generated_tags_not_created = entry.tag_processor_version < self.tag_rules_processor.version
is_auto_generated_tags_not_created = entry.tag_processor_version is None or \
entry.tag_processor_version < self.tag_rules_processor.version
if is_auto_generated_tags_not_created:
generated = self.tag_rules_processor.process_torrent_title(infohash=entry.infohash, title=entry.title)
entry.tag_processor_version = self.tag_rules_processor.version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import json
from unittest.mock import MagicMock
from unittest.mock import MagicMock, Mock

import pytest
from aiohttp.web_app import Application

from ipv8.util import succeed

from pony.orm import db_session

import pytest

from tribler.core.components.metadata_store.db.orm_bindings.channel_node import COMMITTED, TODELETE, UPDATED
from tribler.core.components.metadata_store.db.serialization import REGULAR_TORRENT
from tribler.core.components.metadata_store.restapi.metadata_endpoint import MetadataEndpoint, TORRENT_CHECK_TIMEOUT
from tribler.core.components.metadata_store.restapi.metadata_endpoint_base import MetadataEndpointBase
from tribler.core.components.restapi.rest.base_api_test import do_request
from tribler.core.components.restapi.rest.rest_manager import error_middleware
from tribler.core.components.torrent_checker.torrent_checker.torrent_checker import TorrentChecker
Expand Down Expand Up @@ -174,18 +173,19 @@ async def test_get_entry(rest_api, metadata_store):
Test getting an entry with REST API GET request
"""
for md_type, kwargs in (
(
metadata_store.TorrentMetadata,
{"title": "bla", "infohash": random_infohash(), "tracker_info": "http://sometracker.local/announce"},
),
(
metadata_store.ChannelDescription,
{
"text": json.dumps(
{"description_text": "*{{}bla <\\> [)]// /ee2323㋛㋛㋛ ", "channel_thumbnail": "ffffff.jpg"}
)
},
),
(
metadata_store.TorrentMetadata,
{"title": "bla", "infohash": random_infohash(),
"tracker_info": "http://sometracker.local/announce"},
),
(
metadata_store.ChannelDescription,
{
"text": json.dumps(
{"description_text": "*{{}bla <\\> [)]// /ee2323㋛㋛㋛ ", "channel_thumbnail": "ffffff.jpg"}
)
},
),
):
with db_session:
md = md_type(**kwargs)
Expand Down Expand Up @@ -244,3 +244,21 @@ async def test_check_torrent_query(rest_api, udp_tracker, metadata_store):
"""
infohash = b'a' * 20
await do_request(rest_api, f"metadata/torrents/{infohash}/health?timeout=wrong_value&refresh=1", expected_code=400)


def test_extract_tags():
# Test that in the case of empty `tag_processor_version` no NPE raise
# see: https://github.com/Tribler/tribler/issues/6986
mds_endpoint = MetadataEndpointBase(
MagicMock(),
tags_db=MagicMock(),
tag_rules_processor=MagicMock(
version=1
)
)
entry = MagicMock(
get_type=Mock(return_value=REGULAR_TORRENT),
tag_processor_version=None
)
mds_endpoint.extract_tags(entry)
assert entry.tag_processor_version == 1

0 comments on commit 365b4f3

Please sign in to comment.