uuosio / ascdk

MIT License
12 stars 9 forks source link

Dangerous primary #52

Closed jafri closed 2 years ago

jafri commented 2 years ago
    get primary(): u64 {
        if (!this.isOk()) {
            return 0;
        }

        if (this._primary != UNKNOWN_PRIMARY_KEY) {
            return this._primary;
        }

        let value = this.value;
        this._primary = value!.getPrimaryValue();
        return this._primary;
    }

returning 0 as primary key is dangerous on !isOk()... that may be a valid existing primary key on another iterator

Primary key is always the same, so at no point should it return 0 like that

learnforpractice commented 2 years ago

I think the best practice is to check the iterator before using primary.

What's your recommendation? Should we throw an error if the iterator is invalid?

learnforpractice commented 2 years ago

Improved by f77bccb904df854991fcf9d348433140d68892f7