title: Python: Why is my async function returning None?
body: <p>I am running an API service with fastAPI:</p>
  <p>main.py file, here is the problem. The data variable always returns None. This shouldn't happen:</p>
  <pre><code>@router.post('', name=&quot;invoice:create&quot;, response_model=FullInvoiceResponse, status_code=201)
  async def create_invoice(request: Request, invoice: CreateInvoiceRequest):
      [etc...]
      try:
          data = await helpers.process_invoice_items(invoice.items)
      except:
      [etc...]
  </code></pre>
  <p>helpers.py:</p>
  <pre><code>from logging import error
  
  async def calculate_invoicing(invoice_items: list) -&gt; dict:
      &quot;&quot;&quot;
      Calculate invoice totals grouping items by description and amount.
      :param invoice_items: list
      :return: dict
      &quot;&quot;&quot;
      processed_data = {}
      for item in invoice_items:
          description, amount = itemgetter('description', 'amount')(item)
          key = f&quot;{description}{amount}&quot;.upper().replace(' ', '')
          processed_data.setdefault(key, [item['description'], item['amount'], 0, 0])
  
          processed_data[key][2] += 1
          processed_data[key][3] += processed_data[key][1]
      return processed_data
  
  
  async def generate_report(processed_data: dict) -&gt; list:
      &quot;&quot;&quot;
      Generate report from invoices.items after they being processed
      :param processed_data: dict
      :return: list
      &quot;&quot;&quot;
      report = []
      for value in processed_data.values():
          description, amount, qtt_items, amount_accumulated = value
          report.append({
              'description': description,
              'amount': amount,
              'qtt': qtt_items,
              'total_amount': amount_accumulated,
          })
      return report
  
  async def process_invoice_items(invoice_items: list):
      &quot;&quot;&quot;
      Generate data about invoice.items properly grouped.
      :param invoice_items: list containing data about items in the request
      :return: list contained all items grouped by amount and description
      &quot;&quot;&quot;
      try:
          invoice_data: dict = await calculate_invoicing(invoice_items)
          invoice_report: list = await generate_report(invoice_data)
          return invoice_report
      except TypeError:
          error(&quot;Something wrong happening while grouping invoice.items&quot;)
  
  </code></pre>
  <p>The invoice_items is something like this:</p>
  <pre><code>invoice_items = [
      {
          &quot;chargeable&quot;: &quot;stone.terminal.entry-fee&quot;,
          &quot;description&quot;: &quot;Item xya&quot;,
          &quot;chargeable_id&quot;: &quot;9112c&quot;,
          &quot;amount&quot;: 59.21
      },
      {
          &quot;chargeable&quot;: &quot;stone.terminal.entry-fee&quot;,
          &quot;description&quot;: &quot;Item xyza&quot;,
          &quot;chargeable_id&quot;: &quot;123c&quot;,
          &quot;amount&quot;: 31.92
      },
      {
          &quot;chargeable&quot;: &quot;stone.terminal.entry-fee&quot;,
          &quot;description&quot;: &quot;Item xyzc&quot;,
          &quot;chargeable_id&quot;: &quot;1234c&quot;,
          &quot;amount&quot;: 11.03
      },
      {
          &quot;chargeable&quot;: &quot;stone.terminal.entry-fee&quot;,
          &quot;description&quot;: &quot;Item xya&quot;,
          &quot;chargeable_id&quot;: &quot;9112c&quot;,
          &quot;amount&quot;: 59.21
      },
      {
          &quot;chargeable&quot;: &quot;stone.terminal.entry-fee&quot;,
          &quot;description&quot;: &quot;Item xyza&quot;,
          &quot;chargeable_id&quot;: &quot;123c&quot;,
          &quot;amount&quot;: 31.92
      },
  
  ]
  </code></pre>
  <p>Whenever I run the code in debug mode, the data variable returns None. Is there something wrong I am not noting?</p>