@@ -240,10 +240,36 @@ async def list_drafts(self, limit: int = 10) -> List[Dict[str, Any]]:
240240 # python-substack returns a generator, convert to list
241241 # The API returns all posts, so we need to filter for drafts only
242242 try :
243- all_posts = list (self .client .get_drafts (limit = min (limit * 3 , 50 ))) # Get more to ensure we have enough drafts, but cap at 50
244- logger .debug (f"Retrieved { len (all_posts )} posts from API" )
243+ # Debug: Let's see what client we're using
244+ logger .info (f"Client type: { type (self .client )} " )
245+ logger .info (f"Client class name: { self .client .__class__ .__name__ } " )
246+
247+ # Check publication info
248+ if hasattr (self .client , 'client' ) and hasattr (self .client .client , 'publication_id' ):
249+ logger .info (f"Publication ID: { self .client .client .publication_id } " )
250+ if hasattr (self .client , 'client' ) and hasattr (self .client .client , 'subdomain' ):
251+ logger .info (f"Subdomain: { self .client .client .subdomain } " )
252+
253+ # Try to get the raw API response
254+ raw_result = self .client .get_drafts (limit = min (limit * 3 , 50 ))
255+ logger .info (f"Raw result type: { type (raw_result )} " )
256+
257+ all_posts = list (raw_result ) # Get more to ensure we have enough drafts, but cap at 50
258+ logger .info (f"Retrieved { len (all_posts )} posts from API" )
259+
260+ # If empty, let's try a different approach
261+ if len (all_posts ) == 0 :
262+ logger .warning ("get_drafts returned empty, trying direct API call" )
263+ # Check if we have the underlying client
264+ if hasattr (self .client , 'client' ):
265+ logger .info ("Found underlying client, checking its properties" )
266+ inner_client = self .client .client
267+ logger .info (f"Inner client type: { type (inner_client )} " )
268+ logger .info (f"Inner client dir: { [x for x in dir (inner_client ) if not x .startswith ('_' )][:10 ]} " )
245269 except Exception as e :
246- logger .error (f"Error getting drafts: { e } " )
270+ logger .error (f"Error getting drafts: { type (e ).__name__ } : { e } " )
271+ import traceback
272+ logger .error (traceback .format_exc ())
247273 return []
248274
249275 drafts = []
@@ -256,17 +282,10 @@ async def list_drafts(self, limit: int = 10) -> List[Dict[str, Any]]:
256282 logger .debug (f"Post has title: { post .get ('title' ) is not None } " )
257283 logger .debug (f"Post has post_date: { post .get ('post_date' ) is not None } " )
258284
259- # Check if it's actually a draft (not published)
260- # Drafts have type='draft' or no post_date
261- is_draft = (
262- post .get ('type' ) == 'draft' or
263- (not post .get ('post_date' ) and (post .get ('draft_title' ) or post .get ('title' )))
264- )
265-
266- if is_draft :
267- drafts .append (post )
268- if len (drafts ) >= limit :
269- break
285+ # For debugging: add ALL posts to see what we're getting
286+ drafts .append (post )
287+ if len (drafts ) >= limit :
288+ break
270289
271290 logger .info (f"Returning { len (drafts )} drafts" )
272291 return drafts
0 commit comments