Repository: python-telegram-bot/python-telegram-bot

Issue:
[BUG] v12.4.1 bot.answer_inline_query broken on results=[InlineQueryResultDocument]
### Steps to reproduce
1. Create InlineQueryHandler
2. Create inline request to bot
3. [InlineQueryResultDocument(
    id=uuid4(), document_url='fill with any pdf url', caption='Test', mime_type='application/pdf', reply_markup=None
)] as the results
4. Send the result using update.inline_query.answer

### Expected behaviour
Nothing raised and worked fine on python-telegram-bot==12.3.0.

### Actual behaviour
Raise AttributeError: 'NoneType' object has no attribute 'parse_mode'

### Configuration
**Operating System: WSL2 Ubuntu**


**python, python-telegram-bot & dependencies:**
python3+
python-telegram-bot=12.4.1

``$ python -m telegram``

### Logs
telegram.ext.dispatcher - ERROR - An error was raised while processing the update and an uncaught error was raised while handling the error with an error_handler
Traceback (most recent call last):
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 403, in process_update
    self.dispatch_error(update, e)
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 528, in dispatch_error
    callback(update, CallbackContext.from_error(update, error, self))
  File "/mnt/d/Projects/bot/handler/error/__init__.py", line 55, in error
    raise context.error
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/ext/dispatcher.py", line 390, in process_update
    handler.handle_update(update, self, check, context)
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/ext/handler.py", line 117, in handle_update
    return self.callback(update, context)
  File "/mnt/d/Projects/bot/handler/inline/__init__.py", line 53, in query
    context,
  File "/mnt/d/Projects/bot/libs/decorators.py", line 38, in wrapped
    return func(self, update, context, *args, **kwargs)
  File "/mnt/d/Projects/bot/handler/inline/pdf.py", line 26, in answer
    results=results_list,
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/inline/inlinequery.py", line 103, in answer
    return self.bot.answer_inline_query(self.id, *args, **kwargs)
  File "</mnt/d/Projects/bot/env/lib/python3.6/site-packages/decorator.py:decorator-gen-21>", line 2, in answer_inline_query
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/bot.py", line 67, in decorator
    result = func(*args, **kwargs)
  File "/mnt/d/Projects/bot/env/lib/python3.6/site-packages/telegram/bot.py", line 1515, in answer_inline_query
    res.parse_mode = self.defaults.parse_mode
AttributeError: 'NoneType' object has no attribute 'parse_mode'



Discussion:

Resolving patch:
diff --git a/telegram/bot.py b/telegram/bot.py
--- a/telegram/bot.py
+++ b/telegram/bot.py
@@ -1512,7 +1512,10 @@ def answer_inline_query(self,
 
         for res in results:
             if res._has_parse_mode and res.parse_mode == DEFAULT_NONE:
-                res.parse_mode = self.defaults.parse_mode
+                if self.defaults:
+                    res.parse_mode = self.defaults.parse_mode
+                else:
+                    res.parse_mode = None
             if res._has_input_message_content and res.input_message_content:
                 if (res.input_message_content._has_parse_mode
                         and res.input_message_content.parse_mode == DEFAULT_NONE):


Test patch:
diff --git a/tests/test_bot.py b/tests/test_bot.py
--- a/tests/test_bot.py
+++ b/tests/test_bot.py
@@ -28,7 +28,8 @@
 
 from telegram import (Bot, Update, ChatAction, TelegramError, User, InlineKeyboardMarkup,
                       InlineKeyboardButton, InlineQueryResultArticle, InputTextMessageContent,
-                      ShippingOption, LabeledPrice, ChatPermissions, Poll)
+                      ShippingOption, LabeledPrice, ChatPermissions, Poll,
+                      InlineQueryResultDocument)
 from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter
 from telegram.utils.helpers import from_timestamp, escape_markdown
 
@@ -237,6 +238,67 @@ def test(_, url, data, *args, **kwargs):
                                        switch_pm_text='switch pm',
                                        switch_pm_parameter='start_pm')
 
+    def test_answer_inline_query_no_default_parse_mode(self, monkeypatch, bot):
+        def test(_, url, data, *args, **kwargs):
+            return data == {'cache_time': 300,
+                            'results': [{'title': 'test_result', 'id': '123', 'type': 'document',
+                                         'document_url': 'https://raw.githubusercontent.com/'
+                                         'python-telegram-bot/logos/master/logo/png/'
+                                         'ptb-logo_240.png', 'mime_type': 'image/png',
+                                         'caption': 'ptb_logo'}],
+                            'next_offset': '42', 'switch_pm_parameter': 'start_pm',
+                            'inline_query_id': 1234, 'is_personal': True,
+                            'switch_pm_text': 'switch pm'}
+
+        monkeypatch.setattr('telegram.utils.request.Request.post', test)
+        results = [InlineQueryResultDocument(
+            id='123',
+            document_url='https://raw.githubusercontent.com/python-telegram-bot/logos/master/'
+                         'logo/png/ptb-logo_240.png',
+            title='test_result',
+            mime_type='image/png',
+            caption='ptb_logo',
+        )]
+
+        assert bot.answer_inline_query(1234,
+                                       results=results,
+                                       cache_time=300,
+                                       is_personal=True,
+                                       next_offset='42',
+                                       switch_pm_text='switch pm',
+                                       switch_pm_parameter='start_pm')
+
+    @pytest.mark.parametrize('default_bot', [{'parse_mode': 'Markdown'}], indirect=True)
+    def test_answer_inline_query_default_parse_mode(self, monkeypatch, default_bot):
+        def test(_, url, data, *args, **kwargs):
+            return data == {'cache_time': 300,
+                            'results': [{'title': 'test_result', 'id': '123', 'type': 'document',
+                                         'document_url': 'https://raw.githubusercontent.com/'
+                                         'python-telegram-bot/logos/master/logo/png/'
+                                         'ptb-logo_240.png', 'mime_type': 'image/png',
+                                         'caption': 'ptb_logo', 'parse_mode': 'Markdown'}],
+                            'next_offset': '42', 'switch_pm_parameter': 'start_pm',
+                            'inline_query_id': 1234, 'is_personal': True,
+                            'switch_pm_text': 'switch pm'}
+
+        monkeypatch.setattr('telegram.utils.request.Request.post', test)
+        results = [InlineQueryResultDocument(
+            id='123',
+            document_url='https://raw.githubusercontent.com/python-telegram-bot/logos/master/'
+                         'logo/png/ptb-logo_240.png',
+            title='test_result',
+            mime_type='image/png',
+            caption='ptb_logo',
+        )]
+
+        assert default_bot.answer_inline_query(1234,
+                                               results=results,
+                                               cache_time=300,
+                                               is_personal=True,
+                                               next_offset='42',
+                                               switch_pm_text='switch pm',
+                                               switch_pm_parameter='start_pm')
+
     @flaky(3, 1)
     @pytest.mark.timeout(10)
     def test_get_user_profile_photos(self, bot, chat_id):