theupdateframework / theupdateframework/python-tuf
Metadata API: Metadata "factory" constructors misbehave with inheritance
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 304
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 17
Description
class DerivedMetadata(Metadata):
def ok(self):
print("ok")
md = DerivedMetadata.from_file("root.json")
md.ok() # fails because md type is Metadata, not DerivedMetadata
This seems to happen because the construction path goes
- DerivedMetadata.from_file()
- DerivedMetadata.from_bytes()
- JsonDeserializer.deserialize() here deserializer doesn't know the correct class anymore and calls Metadata.from_dict()
- Metadata.from_dict()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the construction path from DerivedMetadata.from_file() through from_bytes(), JsonDeserializer.deserialize(), and Metadata.from_dict(). Determine where the derived class is lost; done means factory construction preserves the subclass so md.ok() works on the resulting object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100