Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No check on attributes #9

Open
trickeydan opened this issue Sep 9, 2018 · 7 comments
Open

No check on attributes #9

trickeydan opened this issue Sep 9, 2018 · 7 comments

Comments

@trickeydan
Copy link
Contributor

There is no check on inv-set-attr for the spelling, or existence of an attribute. Perhaps we should define what attributes are allowed?

@trickeydan
Copy link
Contributor Author

This is also the case for the value of the attributes

@PeterJCLaw
Copy link
Member

I believe the "lack" of a check on attributes is intentional, so that data about tracked items can be easily added under new keys without needing to wait for the tooling to update.

However as noted this can cause issues when typos happen.

Some thoughts on possible approaches:

  • We could defined a set of known attributes and spell-check any attributes against that list, warning the user if it looks like they've typo'd.
  • We could define sets of attributes with various levels of expectation about their presence, such as:
    • required attributes: without which the inventory is considered invalid and refuses to operate. This would be things like asset_code and description
    • usual attributes: things which are generally expected to be present and emit a warning if missing when that item is changed (i.e: moved explicitly or edited, but perhaps not when moved as a result of its container moving); this would be things like condition (though we should rename that), physical_condition, value, owner
    • other attributes: known attributes which are completely optional
  • We could make the definition of valid attributes be part of the .meta directory in the inventory itself, so that adding new ones is easy, but validation can still be strict

It also seems possible to combine these approaches.

@PeterJCLaw
Copy link
Member

Hrm, so it looks like there is a check for some properties, though only that certain mandatory ones are present:

        # The mandatory properties
        for pname in ["labelled", "description", "value", "condition"]:
            try:
                setattr(self, pname, self.info[pname])
            except KeyError:
                raise ValueError("Part sr{} is missing '{}' property."
                                 .format(self.code, pname))

@trickeydan
Copy link
Contributor Author

My ideal solution to this would be to ship a schema within the repo and use something like Typesystem for validation. This is what SRO are planning for their asset tracker, which is heavily inspired by our tooling here.

@PeterJCLaw
Copy link
Member

Nice library, shame it's Python 3.6+ though. We're (for the moment at least) somewhat tied to supporting a wider range of versions than that.

@trickeydan
Copy link
Contributor Author

Nice library, shame it's Python 3.6+ though. We're (for the moment at least) somewhat tied to supporting a wider range of versions than that.

There are a few similar libraries knocking around, not quite as nice as Typesystem though. e.g Schematics(2.7, 3.3+). We're able to get away with 3.6+ at SRO because we're introducing a web interface for it.

@trickeydan
Copy link
Contributor Author

We seem to be 3.6+ on this project now.

I can highly recommend pydantic for data validation. Notably, we use it in other SR projects too, (e.g astoria)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants