Skip to content

[FIX] dfe: fix DfeClient.send() crash when wrap_response=True#145

Merged
rvalyi merged 3 commits intoakretion:masterfrom
Engenere:fix/dfe-client-wrap-response
Feb 11, 2026
Merged

[FIX] dfe: fix DfeClient.send() crash when wrap_response=True#145
rvalyi merged 3 commits intoakretion:masterfrom
Engenere:fix/dfe-client-wrap-response

Conversation

@felipemotter
Copy link
Copy Markdown
Contributor

@felipemotter felipemotter commented Feb 10, 2026

Resumo

Corrige o crash AttributeError: 'WrappedResponse' object has no attribute 'body' ao usar DfeClient.consultar_distribuicao() com wrap_response=True.

Trabalho em desenvolvimento — aberto como draft para discussão.

Depende de: #133 (cherry-pick do commit 21f8a39 para fix da versão do SOAP envelope)

Como reproduzir

  1. Criar um DfeClient com wrap_response=True (modo de compatibilidade com erpbrasil.edoc)
  2. Chamar consultar_distribuicao()
  3. O método send() chama super().send() que retorna um WrappedResponse
  4. Em seguida tenta acessar response.body, que não existe no WrappedResponse
  • Antes do fix: AttributeError: 'WrappedResponse' object has no attribute 'body'
  • Após o fix: resposta retornada corretamente com resposta e retorno preenchidos

Causa raiz

FiscalClient.send() (brazil_fiscal_client) retorna tipos diferentes conforme wrap_response:

  • False → SOAP envelope parseado diretamente (tem .body)
  • TrueWrappedResponse (tem .resposta com o envelope, .retorno com a resposta HTTP)

DfeClient.send() acessava response.body incondicionalmente, falhando no modo wrap_response=True.

Solução

Dois commits:

  1. fix version for nfeDistribuicaoDFe soap envelope (cherry-pick da SOAP support for NFe  #133, @antoniospneto) — corrige versao de "4.00" para "1.01", compatível com o schema distDFeInt.

  2. fix DfeClient.send() crash when wrap_response=True — detecta se o retorno é WrappedResponse (.resposta) ou envelope direto, mantendo compatibilidade com quem migra de erpbrasil.edoc para brazil_fiscal_client sem precisar de um refactor grande.

antoniospneto and others added 2 commits February 10, 2026 15:11
wrap_response=True keeps backward compatibility with erpbrasil.edoc
so that consumers migrating to brazil_fiscal_client don't need a
large refactor. In that mode, FiscalClient.send() returns a
WrappedResponse whose parsed SOAP envelope is in .resposta.
DfeClient.send() was accessing response.body directly, which does
not exist on WrappedResponse, causing:
    AttributeError: 'WrappedResponse' object has no attribute 'body'
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.39%. Comparing base (3ef6e44) to head (111d09a).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #145      +/-   ##
==========================================
+ Coverage   94.02%   94.39%   +0.36%     
==========================================
  Files          10       10              
  Lines         335      357      +22     
  Branches       29       30       +1     
==========================================
+ Hits          315      337      +22     
  Misses         10       10              
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felipemotter felipemotter marked this pull request as ready for review February 10, 2026 19:09
@antoniospneto
Copy link
Copy Markdown
Contributor

@rvalyi essa correção é importante pra gente avançar no módulo do DFe

Valeu @felipemotter!

Ensure consultar_distribuicao returns a WrappedResponse with the
parsed content in .resposta and HTTP data in .retorno when using
the erpbrasil.edoc compatibility mode (wrap_response=True).
@felipemotter
Copy link
Copy Markdown
Contributor Author

coloquei um teste para ajudar no codecov

Copy link
Copy Markdown
Member

@rvalyi rvalyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valeu @felipemotter . Eu tinha bolado o sistema do wrap_response depois da primeira versão do client de DFe e acabei esquecendo isso. Vamos ver ainda se esse API do wrap_response que visa a imitar o API do erpbrasil.edoc possa ser melhorado, mas por enquanto podemos mesclar isso sem problema.

@rvalyi rvalyi merged commit 7cf14ca into akretion:master Feb 11, 2026
9 of 10 checks passed
@antoniospneto
Copy link
Copy Markdown
Contributor

@rvalyi Consegue publicar uma nova versão com essas alterações? valeuuu!

@felipemotter felipemotter deleted the fix/dfe-client-wrap-response branch February 18, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants