Bug in WARCRecord.__repr__()

Open
#3 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start by reproducing the shown WARCHeader/WARCRecord snippet and reading init.py at WARCRecord.repr, WARCRecord.getitem, and WARCHeader.getitem. Determine whether the lookup chain or repr is responsible; done means the shown r expression produces a representation without the reported KeyError.

Written by the indexing model from the issue text.

Description

The line in repr:

return "<WARCRecord: type=%r record_id=%s>" % (self['type'], self['record_id'])

results in an error. I don't know if the above line is wrong or whether there's a bug in how the attribute lookup chain is supposed to work. Changing the above line to this works though:

return "<WARCRecord: type=%r record_id=%s>" % (self.header.type, self.header.record_id)

Traceback below.


h=WARCHeader({"WARC-Type": "response"}, defaults=True)
r = WARCRecord(h)
r
Traceback (most recent call last):
File "", line 1, in
File "init.py", line 186, in repr
return "<WARCRecord: type=%r record_id=%s>" % (self['type'], self['record_id'])
File "init.py", line 172, in getitem
return self.header[name]
File "init.py", line 40, in getitem
return self._d[name.lower()]
KeyError: 'type'

Dominant language
Python
Stars
251
Forks
114
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from internetarchive/warc

All issues in internetarchive/warc

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.