Skip to content

fix(br_bcb_estban): add cnpj_basico to agencia unique key - #1846

Merged
rdahis merged 1 commit into
mainfrom
fix/br_bcb_estban-agencia-unique-key
Aug 19, 2026
Merged

rdahis merged 1 commit into
mainfrom
fix/br_bcb_estban-agencia-unique-key

Conversation

@rdahis

@rdahis rdahis commented Aug 19, 2026

Copy link
Copy Markdown
Member

Problema

O flow br_bcb_estban__agencia falha no passo dbt test, no teste
dbt_utils.unique_combination_of_columns:

Got 45 results, configured to fail if != 0

Última ocorrência: run ivory-seahorse (acf10912-9a0b-449d-ac22-1b1b5205a5f1),
2026-08-18. O poll, o download, a limpeza, o upload e o dbt run funcionaram —
a correção do PR #1783 está OK. A falha é só no teste.

Causa

Não é duplicação de ingestão. Todos os 45 grupos duplicados (585 linhas) estão em
Brasília (id_municipio = 5300108), onde treze instituições distintas
compartilham o mesmo cnpj_agencia
: 00000000000191, o CNPJ do Banco do
Brasil. O valor vem direto da coluna AGENCIA da fonte — a limpeza em
pipelines/crawler/bcb_estban/utils.py só remove apóstrofos.

Ou seja, a chave do teste está incompleta: cnpj_agencia sozinho não identifica
a linha.

Como o teste é escopado em __most_recent_year_month__, ele falha sempre que a
competência mais recente carrega a colisão — 3 dos últimos 5 meses:

competência grupos duplicados (chave atual)
2025-11 45 (também em prod)
2025-12 0
2026-01 45
2026-02 45
2026-03 45

Correção

Incluir cnpj_basico na chave — a mesma coluna que a tabela municipio já usa.

Verificado no BigQuery: 0 grupos duplicados com a chave nova, tanto em
basedosdados-dev 2026-03 quanto em basedosdados 2025-11.

Notas

  • Só mexe em teste; nenhum modelo .sql muda, então não precisa de
    table-approve
    nem de deploy-flow. O worker clona main em tempo de
    execução, então basta o merge.
  • Sem isso, armar o schedule do agencia significa falha em toda run.
  • Fora do escopo, mas registrado: a tabela municipio tem um carve-out
    pré-existente (id_municipio not in ('5300108')) que mascara 270 grupos
    duplicados em 2026-03 — mesma causa raiz, em Brasília.

O teste dbt_utils.unique_combination_of_columns da tabela `agencia`
falhava com 45 grupos duplicados (585 linhas) na competência mais
recente, derrubando o flow `br_bcb_estban__agencia` no passo `dbt test`
(run `ivory-seahorse`, 2026-08-18).

Não é duplicação de ingestão: em Brasília (id_municipio 5300108) treze
instituições distintas compartilham o mesmo `cnpj_agencia`
(00000000000191, CNPJ do Banco do Brasil). O valor vem direto da coluna
`AGENCIA` da fonte — a limpeza apenas remove apóstrofos. Ou seja, a
chave do teste estava incompleta: `cnpj_agencia` sozinho não identifica
a linha.

Incluir `cnpj_basico` na chave — a mesma coluna que a tabela `municipio`
já usa — torna a combinação única. Verificado no BigQuery: 0 grupos
duplicados em basedosdados-dev 2026-03 e em basedosdados 2025-11 (os
meses afetados).
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@rdahis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7f1786a3-9408-46bc-a08d-d33ea3da7168

📥 Commits

Reviewing files that changed from the base of the PR and between 48c339e and 9956d15.

📒 Files selected for processing (1)
  • models/br_bcb_estban/schema.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rdahis
rdahis merged commit 8f75e30 into main Aug 19, 2026
7 of 8 checks passed
@rdahis
rdahis deleted the fix/br_bcb_estban-agencia-unique-key branch August 19, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant