Jump to content

Remove Item when BaseItem is NULL ?


mickle026

Recommended Posts

mickle026

Is there anyway to remove a database item when BaseItem is NULL ?

I keep getting a recurring error is one of my apps, I can handle the error but I'd rather like to correct it, vacuum is not removing these.

I can already remove corrupt entries using LibraryManager.DeleteItem, but I have to supply a basitem.

How can I do that on a record where baseitem is throwing an error becase it is null?

I seem to have a few records in my database that are completely empty.

29.Sep.2023 - 16:38:16 !!! Threw an Outer exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Kodi_actors_Folders.Kodi_actors_Folders.Get(exportActorsToActorFolders result)
29.Sep.2023 - 16:38:16 !!! at: MovieCount-20802 - MovieName-
29.Sep.2023 - 16:38:16 !!! in Containing Folder: 
29.Sep.2023 - 16:38:16 Attempting remove corrupt entry from the Database.
29.Sep.2023 - 16:38:16 Removal From the Database Failed!
System.ArgumentNullException: Value cannot be null. (Parameter 'item')
   at Emby.Server.Implementations.Library.LibraryManager.DeleteItem(BaseItem item, DeleteOptions options, Boolean notifyParentItem)
   at Kodi_actors_Folders.Kodi_actors_Folders.Get(exportActorsToActorFolders result)

 

Link to comment
Share on other sites

mickle026
21 minutes ago, Luke said:

Hi, well you can’t pass in null to the delete method.

Appreciate that, but like the original question, how can I remove these records from the db?

42 minutes ago, mickle026 said:

How can I do that on a record where baseitem is throwing an error becase it is null?

 

Link to comment
Share on other sites

mickle026

Thanks Luke but you are missing the point of the question - still not what I asked.

I cannot get the item to delete if it is null, the question is , how can i remove these from the db, even if its an sql command in sql lite ?  You probably believe this cannot happen, but it does.

I have got a list of movies already , but one or more of the entries are null, ie one of the records fetched by library manager is null. - How can I get the item then? - I dont believe you can via the librarymanager.
All the rest of the records are fine, just a few throw a null error, it doesn't get past libraryManager.GetItemById(SingleMovie) because one or more of the records is null.

Is this my error or something internal within librarymanager? - maybe returning an empty dataset? - either I have an empty record or there is an error in librarymanager.

The weird thing is , that its not always in the same place.

The test server I am testing on, only has a library of movies, There are no Series or Episodes on it.

 var xMovies = libraryManager.GetInternalItemIds(new InternalItemsQuery
{
	IncludeItemTypes = new[] { "Episode" , "Series", "Movie" } }
});

int counter;
foreach (var SingleMovie in xMovies)
{
	try
    {
       counter++;
       BaseItem IndividualMovie = libraryManager.GetItemById(SingleMovie);
      // more code but it doesnt get there if a singlemovie record is null !
      // error is thrown by BaseItem IndividualMovie line of code, and this record is fetched (or created) by libraryManager
    }
  catch
  {
   	// Throw the error to the log
    log($"Error occured at {counter}");
  }
}

obviously I can catch and continue, but I would really like to know why this is happening in the first place

Edited by mickle026
Link to comment
Share on other sites

OK yea I'm not sure. It would probably require looking at the database to find out why it's unable to retrieve it, thus causing null to come back. If it's only on a test system that you use for plugin development then you may just want to chalk it up to heavy tinkering and not worry about it or delete the entire database.

Link to comment
Share on other sites

mickle026

It happens in both my Test server and my Main everyday use server.  I am using my test server as an example because thats where im a logging it mostly.  I have been getting this odd seemingly random null error since I first started plugin dev.  Its only recently I have tracked it down to where its is exactly happening.

So I really dont know what has caused it, or causes it.  Maybe corruption like IO failure or Machine reboots, maybe an sql error, maybe even dare I say it .. Emby core.  I really have no clue, and its one of those things that must be very hard to find as its took me nearly 2 years to even trace it back to where its happening.

My main everyday use server has gone through many updates, so I have no clue how or why this was introduced.  Only that it happens and is there.  Im am definately not going to delete and rebuild the everyday use server db unless I ever have to.  I would also prefer not to do this for the test server either if possible (although I could).

So this is something I want to fix , even if it is manually or maybe like emby to have a repair db option.  If these records were removed automatically by the core, then they would regenerate correctly on a library scan.  If I did it manually in an sql editor, the same would happen.

With something like this, but I dont know what the correct code would be, as I am not an expert in this.  I think that this should do it

mysql> delete from Tablename where Title='' OR Title IS NULL;

finding them with

select *from MediaItems where Name='' OR Name IS NULL;
select *from MediaItems where Id='' OR Id IS NULL;
select *from MediaItems where guid='' OR guid IS NULL;

0 rows returned in 3192ms from: select *from MediaItems where Name='' OR Name IS NULL;
0 rows returned in 1ms from: select *from MediaItems where Id='' OR Id IS NULL;
0 rows returned in 0ms from: select *from MediaItems where guid='' OR guid IS NULL;

However running in DB Browser, I find no errors at all.

This is just weird, it happens in the plugin and is a returned record, but doent appear to me to even be in the database at all ????

or am I querying the wrong things? - what does db key this actually pull from the db?

 var xMovies = libraryManager.GetInternalItemIds(new InternalItemsQuery
{
	IncludeItemTypes = new[] { "Episode" , "Series", "Movie" } }
});

At the moment it looks to me that this is an Error in Emby core, however I cannot actually say that because I could be doing something wrong in the lookups directly from the db.

I probably just have to handle this error and ignore that its there

:(

Link to comment
Share on other sites

You should be able to find which row it is by logging the Id that you're passing into GetItemById.

Take that Id, do select * from mediaitems where id=@id and then copy paste the result here. Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
mickle026

@Luke

I Finally found where stray entries are happening - tested with People Names and it is EMBY itself doing this, so I am guessing that it probably is with Movie Names too

If you edit here in this editor window (The pop up from the pencil icon in the main display), the old entry persists in the db:

Screenshot2023-10-15at20-43-04MIKE-PC.png.2415f87994e2cfffcea40c1990a8a8a3.png

Example:

So if I change Cherry Rain to Cherry Snow and there are no other Cherry Rain(s) in my db Cherry Rain will change to Cherry Snow, but Cherry Rain remains in the db attached to nothing.  Search will bring up Cherry Rain that doesnt appear in anything, Fetching internally the data will also fetch Cherry Rain.
Exporting the *only* people will also export Cherry Rain.

I have not fully investigated this, but it looks to me like you create a new db entry and attach it to the parent but dont remove the old one if it doesnt have a parent. (or this is failing)

When you edit the idividual items PRIMARY name in metadata editor - the old name/entry is left behind in the db

Edited by mickle026
Link to comment
Share on other sites

There's nothing wrong with leaving that person in the database, although yes it does get cleaned up, just not at that time.

Link to comment
Share on other sites

mickle026
9 minutes ago, Luke said:

There's nothing wrong with leaving that person in the database, although yes it does get cleaned up, just not at that time.

So I have items, People and Movies that have been hanging in the db for months.

When do they get cleaned up? - and will a server restart prevent it if they are not cleaned before the restart.

Several restarts have happened since I corrected some peoples names, several days have passed and the old ones are still there

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...