mirror of
https://github.com/beetbox/beets.git
synced 2026-02-15 20:03:25 +01:00
db: replace _get with from_id
This commit is contained in:
parent
93dae86356
commit
bbedf5b3fb
4 changed files with 10 additions and 10 deletions
|
|
@ -652,7 +652,7 @@ class Model(ABC, Generic[D]):
|
|||
if not self._dirty and self.db.revision == self._revision:
|
||||
# Exit early
|
||||
return
|
||||
stored_obj = self.db._get(type(self), self.id)
|
||||
stored_obj = self.db.from_id(type(self), self.id)
|
||||
assert stored_obj is not None, f"object {self.id} not in DB"
|
||||
self._values_fixed = LazyConvertDict(self)
|
||||
self._values_flex = LazyConvertDict(self)
|
||||
|
|
@ -1306,7 +1306,7 @@ class Database:
|
|||
sort if sort.is_slow() else None, # Slow sort component.
|
||||
)
|
||||
|
||||
def _get(
|
||||
def from_id(
|
||||
self,
|
||||
model_cls: type[AnyModel],
|
||||
id,
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ class Library(dbcore.Database):
|
|||
|
||||
Return `None` if no match is found.
|
||||
"""
|
||||
return self._get(Item, id)
|
||||
return self.from_id(Item, id)
|
||||
|
||||
def get_album(self, item_or_id):
|
||||
"""Given an album ID or an item associated with an album, return
|
||||
|
|
@ -145,4 +145,4 @@ class Library(dbcore.Database):
|
|||
album_id = item_or_id.album_id
|
||||
if album_id is None:
|
||||
return None
|
||||
return self._get(Album, album_id)
|
||||
return self.from_id(Album, album_id)
|
||||
|
|
|
|||
|
|
@ -1073,7 +1073,7 @@ def show_model_changes(
|
|||
restrict the detection to. `always` indicates whether the object is
|
||||
always identified, regardless of whether any changes are present.
|
||||
"""
|
||||
old = old or new._db._get(type(new), new.id)
|
||||
old = old or new._db.from_id(type(new), new.id)
|
||||
|
||||
# Keep the formatted views around instead of re-creating them in each
|
||||
# iteration step
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ class ModelTest(unittest.TestCase):
|
|||
def test_retrieve_by_id(self):
|
||||
model = ModelFixture1()
|
||||
model.add(self.db)
|
||||
other_model = self.db._get(ModelFixture1, model.id)
|
||||
other_model = self.db.from_id(ModelFixture1, model.id)
|
||||
assert model.id == other_model.id
|
||||
|
||||
def test_store_and_retrieve_flexattr(self):
|
||||
|
|
@ -319,7 +319,7 @@ class ModelTest(unittest.TestCase):
|
|||
model.foo = "bar"
|
||||
model.store()
|
||||
|
||||
other_model = self.db._get(ModelFixture1, model.id)
|
||||
other_model = self.db.from_id(ModelFixture1, model.id)
|
||||
assert other_model.foo == "bar"
|
||||
|
||||
def test_delete_flexattr(self):
|
||||
|
|
@ -342,11 +342,11 @@ class ModelTest(unittest.TestCase):
|
|||
model.foo = "bar"
|
||||
model.store()
|
||||
|
||||
model = self.db._get(ModelFixture1, model.id)
|
||||
model = self.db.from_id(ModelFixture1, model.id)
|
||||
del model["foo"]
|
||||
model.store()
|
||||
|
||||
model = self.db._get(ModelFixture1, model.id)
|
||||
model = self.db.from_id(ModelFixture1, model.id)
|
||||
assert "foo" not in model
|
||||
|
||||
def test_delete_non_existent_attribute(self):
|
||||
|
|
@ -387,7 +387,7 @@ class ModelTest(unittest.TestCase):
|
|||
model1["flex_field"] = True
|
||||
model1.add(self.db)
|
||||
|
||||
model2 = self.db._get(ModelFixture1, model1.id)
|
||||
model2 = self.db.from_id(ModelFixture1, model1.id)
|
||||
assert "flex_field" in model2
|
||||
|
||||
del model1["flex_field"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue