Ticket #4130 (new defect)
Ticket Component Interface Fails to Properly Check for Existing Component
| Reported by: | pacopablo | Owned by: | jonas |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.12 |
| Component: | ticket system | Version: | 0.10 |
| Severity: | normal | Keywords: | model component |
| Cc: | pacopablo@… |
Description
When using the ticket.model.Component class, it will raise a TracError if passed the name of a non-existent component on instantiation.
If the component is instantiated with an existing component name, it will assert an error if one tries to call insert(). However, if one instantiates the object with out a name, and then sets the name and owner after the fact, and then calls insert(), no checking of duplicate rows is done.
Possible borkage:
c = Component(env) c.name = 'component1' c.owner = 'sombody' c.insert()
The API should be modified to either raise a TracError? in the case in question, and/or provide a method for discovering whether or not a Component exist.
Personally, I think that the following would be desired behavior:
c = Component(env, 'new component') c.insert()
Where the insert() is a noop if the component already exists. The exists property could also reflect whether or not the Component instance references an existing component or not.
c = Component(env, 'new component') if not c.exists: c.insert()
I find this preferable to:
try: c = Component(env, 'new component') except TracError: c = Component(env) c.name = 'new component' c.insert()
