Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue 209: Undefined method 'type' for nil:NilClass #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mherasymiv-blackbird
Copy link

@mherasymiv-blackbird mherasymiv-blackbird commented Feb 8, 2024

Pull Request Template

Description

Issue 209: Undefined method 'type' for nil:NilClass
This error occurs when record key doesn't exist in the actual schema.
Seems that in old versions such gaps would let it pass, but newer versions have more validation and it starts failing with this error which makes it being not backward compatible and difficult to debug.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • It reproduced during major Ruby (deimos-ruby (1.3.0.pre.beta5) to deimos-ruby (1.23.0)) upgrade: https://github.com/wishabi/feedel/pull/1798
    for the following schema.
    As it appeared the schema was way outdated and the issue was fixed by updating schema.
    This fix is for a proper error handling which should ease the debugging when this kind of situation happen.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added a line in the CHANGELOG describing this change, under the UNRELEASED heading
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Deimos
VERSION = '1.23.3'
VERSION = '1.23.4'
Copy link
Member

Choose a reason for hiding this comment

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

Please don't bump the version as part of the PR - we can do that separately.

@@ -29,6 +29,9 @@ def coerce_union(type, val)
def coerce_record(type, val)
record = val.map do |name, value|
field = type.fields.find { |f| f.name == name }

raise "Field #{name} does not exist in Avro::Schema" if field.nil?
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test for this?

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.

2 participants