Skip to content

Commit

Permalink
Setting field type suppresses the auto-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Nov 2, 2023
1 parent 243d71c commit 9da771b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 1.4.5
* fix: Setting field type by `--type` suppresses the auto-detection.

## 1.4.4 (2023-05-26)
* fix: OTRS sending with no attachment forwarded

Expand Down
1 change: 1 addition & 0 deletions convey/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, name, is_chosen=True, source_field: Optional[Field] = None, s
self.merge_operation = merge_operation
"This field is merged from a remote file"
self.possible_types = {}
"Possible types the field can be of. If self.type is specified, it is just self.type."
if isinstance(name, Type):
self.type = name
else:
Expand Down
9 changes: 6 additions & 3 deletions convey/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

if TYPE_CHECKING:
from .field import Field
from .parser import Parser

logger = logging.getLogger(__name__)


class Identifier:

def __init__(self, parser):
def __init__(self, parser: Parser):
self.parser = parser
self.graph = None

Expand Down Expand Up @@ -239,6 +240,10 @@ def identify_fields(self, quiet=False):
return False

for i, field in enumerate(self.parser.fields):
if field.type:
field.possible_types = {field.type : 100}
continue

possible_types = {}
for type_ in Types.get_guessable_types():
score = type_.check_conformity(samples[i], self.parser.has_header, field)
Expand All @@ -247,8 +252,6 @@ def identify_fields(self, quiet=False):
# Use with Python3.8
# possible_types = {type_: score for type_ in Types.get_guessable_types()
# if (score := type_.check_conformity(samples[i], self.parser.has_header, field))}
if field.type:
possible_types[field.type] = 100

if possible_types: # sort by biggest score - biggest probability the column is of this type
field.possible_types = {k: v for k, v in sorted(possible_types.items(), key=lambda k: k[1], reverse=True)}
Expand Down
4 changes: 2 additions & 2 deletions convey/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def hostname_ips(val):
try:
Checker.hostname_ips_cache[val] = list(
{addr[4][0] for addr in timeout(15, socket.getaddrinfo, val, None)})
except (TimeoutError, OSError) as e:
except (TimeoutError, OSError, ValueError) as e:
Checker.hostname_ips_cache[val] = []
return Checker.hostname_ips_cache[val]

Expand All @@ -147,7 +147,7 @@ def hostname_ip(cls, val):
if val not in cls.hostname_cache:
try:
cls.hostname_cache[val] = timeout(3, socket.gethostbyname, val)
except (TimeoutError, OSError) as e:
except (TimeoutError, OSError, ValueError) as e:
logger.warning(f"Hostname {val}: {e}")
cls.hostname_cache[val] = []
return cls.hostname_cache[val]
Expand Down

0 comments on commit 9da771b

Please sign in to comment.