theupdateframework / theupdateframework/python-tuf

Metadata API: Metadata "factory" constructors misbehave with inheritance

Open
#1,665 11 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.