mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Add workaround for SQLiteSession needing save after init
This commit is contained in:
		
							parent
							
								
									378ccd17bf
								
							
						
					
					
						commit
						8190a92aae
					
				| 
						 | 
					@ -523,6 +523,12 @@ class TelegramBaseClient(abc.ABC):
 | 
				
			||||||
                except OSError:
 | 
					                except OSError:
 | 
				
			||||||
                    print('Failed to connect')
 | 
					                    print('Failed to connect')
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					        # Workaround specific to SQLiteSession, which sometimes need to persist info after init.
 | 
				
			||||||
 | 
					        # Since .save() is now async we can't do that in init. Instead we do it in the first connect.
 | 
				
			||||||
 | 
					        if isinstance(self.session, SQLiteSession) and not self.session._init_saved:
 | 
				
			||||||
 | 
					            await self.session.save()
 | 
				
			||||||
 | 
					            self.session._init_saved = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not await self._sender.connect(self._connection(
 | 
					        if not await self._sender.connect(self._connection(
 | 
				
			||||||
            self.session.server_address,
 | 
					            self.session.server_address,
 | 
				
			||||||
            self.session.port,
 | 
					            self.session.port,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,7 @@ class SQLiteSession(MemorySession):
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
        self.filename = ':memory:'
 | 
					        self.filename = ':memory:'
 | 
				
			||||||
        self.save_entities = True
 | 
					        self.save_entities = True
 | 
				
			||||||
 | 
					        self._init_saved = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if session_id:
 | 
					        if session_id:
 | 
				
			||||||
            self.filename = session_id
 | 
					            self.filename = session_id
 | 
				
			||||||
| 
						 | 
					@ -55,7 +56,7 @@ class SQLiteSession(MemorySession):
 | 
				
			||||||
                self._upgrade_database(old=version)
 | 
					                self._upgrade_database(old=version)
 | 
				
			||||||
                c.execute("delete from version")
 | 
					                c.execute("delete from version")
 | 
				
			||||||
                c.execute("insert into version values (?)", (CURRENT_VERSION,))
 | 
					                c.execute("insert into version values (?)", (CURRENT_VERSION,))
 | 
				
			||||||
                self.save()
 | 
					                self._init_saved = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # These values will be saved
 | 
					            # These values will be saved
 | 
				
			||||||
            c.execute('select * from sessions')
 | 
					            c.execute('select * from sessions')
 | 
				
			||||||
| 
						 | 
					@ -109,7 +110,7 @@ class SQLiteSession(MemorySession):
 | 
				
			||||||
            c.execute("insert into version values (?)", (CURRENT_VERSION,))
 | 
					            c.execute("insert into version values (?)", (CURRENT_VERSION,))
 | 
				
			||||||
            self._update_session_table()
 | 
					            self._update_session_table()
 | 
				
			||||||
            c.close()
 | 
					            c.close()
 | 
				
			||||||
            self.save()
 | 
					            self._init_saved = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def clone(self, to_instance=None):
 | 
					    def clone(self, to_instance=None):
 | 
				
			||||||
        cloned = super().clone(to_instance)
 | 
					        cloned = super().clone(to_instance)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user